diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 043a63e35..0d4781619 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -203,7 +203,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t report_error("gasmix %d for tank %d doesn't match", tank.gasmix, i); } } - if (!IS_FP_SAME(tank.volume, 0.0)) + if (!nearly_0(tank.volume)) no_volume = false; // this new API also gives us the beginning and end pressure for the tank @@ -212,8 +212,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t // that matches the consumption and an end pressure of always 0 // In order to make this work, we arbitrary shift this up by 30bar so the // rest of the code treats this as if they were valid values - if (!IS_FP_SAME(tank.beginpressure, 0.0)) { - if (!IS_FP_SAME(tank.endpressure, 0.0)) { + if (!nearly_0(tank.beginpressure)) { + if (!nearly_0(tank.endpressure)) { cyl.start.mbar = lrint(tank.beginpressure * 1000); cyl.end.mbar = lrint(tank.endpressure * 1000); } else if (same_string(devdata->vendor, "Uwatec")) { diff --git a/core/subsurface-string.h b/core/subsurface-string.h index 90ee4fc8c..15dcbb728 100644 --- a/core/subsurface-string.h +++ b/core/subsurface-string.h @@ -24,12 +24,18 @@ #define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) <= 0.000001 * MAX(fabs(_a), fabs(_b))) -// string handling #ifdef __cplusplus extern "C" { #endif +static inline bool nearly_0(double fp) +{ + return fabs(fp) <= 1e-6; +} + +// string handling + static inline bool same_string(const char *a, const char *b) { return !strcmp(a ?: "", b ?: ""); diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index a123935d3..6a859ff4b 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -195,7 +195,7 @@ void DownloadFromDCWidget::updateProgressBar() ui.progressText->setText(progress_bar_text); #endif } else { - if (IS_FP_SAME(progress_bar_fraction, 0.0)) { + if (nearly_0(progress_bar_fraction)) { // while we are waiting to connect, set the maximum to 0 so we get a busy indication ui.progressBar->setMaximum(0); ui.progressBar->setFormat(tr("Connecting to dive computer"));