From 56e755b7119b494d2d875c617500d0299ae06a35 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sat, 7 Oct 2017 21:39:20 +0300 Subject: Use lrint() for all degrees_t related rounding In certain places the '(int)' cast is used, while in other the llrint() or lrint() functions. Make the conversation from degrees in the 'double' form to the 'int' degrees_t consistent using lrint(). lrint() is the function which should give the best results, because it accepts a 'double' and results in a 'long' even if degrees_t is 'int'. If the truncation from 'long' to 'int' is discarding some of the precision then the next step would be to turn degrees_t into a 64bit signed integer type. Possible fix for #625. Signed-off-by: Lubomir I. Ivanov --- desktop-widgets/locationinformation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 542d268fb..6382378da 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -187,8 +187,8 @@ void LocationInformationWidget::acceptChanges() if (!ui.diveSiteCoordinates->text().isEmpty()) { double lat, lon; parseGpsText(ui.diveSiteCoordinates->text(), &lat, &lon); - currentDs->latitude.udeg = (int)(lat * 1000000.0); - currentDs->longitude.udeg = (int)(lon * 1000000.0); + currentDs->latitude.udeg = lrint(lat * 1000000.0); + currentDs->longitude.udeg = lrint(lon * 1000000.0); } if (dive_site_is_empty(currentDs)) { LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs)); @@ -265,8 +265,8 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString if (!same_string(qPrintable(text), coords)) { double latitude, longitude; if (parseGpsText(text, &latitude, &longitude)) { - displayed_dive_site.latitude.udeg = (int)(latitude * 1000000); - displayed_dive_site.longitude.udeg = (int)(longitude * 1000000); + displayed_dive_site.latitude.udeg = lrint(latitude * 1000000); + displayed_dive_site.longitude.udeg = lrint(longitude * 1000000); markChangedWidget(ui.diveSiteCoordinates); emit coordinatesChanged(); ui.geoCodeButton->setEnabled(latitude != 0 && longitude != 0); -- cgit v1.2.3-70-g09d2