From e65c7cedc8a948c14c19a1f1ff054703651ba7f9 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 1 May 2024 21:01:06 +1200 Subject: [PATCH] Refactoring: Improve Naming of FRACTION and SIGNED_FRAC defines. Make it more obvious that the FRACTION and SIGNED_FRAC defines return a tuple / triplet of values. Fixes https://github.com/subsurface/subsurface/pull/4171#discussion_r1585941133 Complained-about-by: @bstoeger Signed-off-by: Michael Keller --- backend-shared/exportfuncs.cpp | 2 +- core/divelist.c | 4 ++-- core/gaspressures.c | 4 ++-- core/libdivecomputer.cpp | 2 +- core/membuffer.cpp | 4 ++-- core/planner.cpp | 2 +- core/plannernotes.cpp | 22 +++++++++++----------- core/profile.cpp | 2 +- core/save-git.cpp | 20 ++++++++++---------- core/save-html.cpp | 6 +++--- core/save-profiledata.c | 6 +++--- core/save-xml.cpp | 22 +++++++++++----------- core/string-format.cpp | 2 +- core/uemis.c | 6 +++--- core/units.h | 4 ++-- qt-models/diveplannermodel.cpp | 6 +++--- 16 files changed, 57 insertions(+), 57 deletions(-) diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index 846530499..7bc545ae5 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -181,7 +181,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall site ? put_format(&buf, "\\def\\%sgpslon{%f}\n", ssrf, site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n"); put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model); put_format(&buf, "\\def\\%scountry{%s}\n", ssrf, country ?: ""); - put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION(dive->duration.seconds, 60)); + put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION_TUPLE(dive->duration.seconds, 60)); put_format(&buf, "\n%% Dive Profile Details:\n"); dive->maxtemp.mkelvin ? put_format(&buf, "\\def\\%smaxtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->maxtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%smaxtemp{}\n", ssrf); diff --git a/core/divelist.c b/core/divelist.c index ee67d77aa..30a4de16e 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -561,7 +561,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p } add_segment(ds, surface_pressure, air, surface_time, 0, OC, prefs.decosac, in_planner); #if DECO_CALC_DEBUG & 2 - printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60)); + printf("Tissues after surface intervall of %d:%02u:\n", FRACTION_TUPLE(surface_time, 60)); dump_tissues(ds); #endif } @@ -598,7 +598,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p } add_segment(ds, surface_pressure, air, surface_time, 0, OC, prefs.decosac, in_planner); #if DECO_CALC_DEBUG & 2 - printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60)); + printf("Tissues after surface intervall of %d:%02u:\n", FRACTION_TUPLE(surface_time, 60)); dump_tissues(ds); #endif } diff --git a/core/gaspressures.c b/core/gaspressures.c index 8bbc869e4..3e440c5df 100644 --- a/core/gaspressures.c +++ b/core/gaspressures.c @@ -102,8 +102,8 @@ static void dump_pr_track(int cyl, pr_track_t *track_pr) printf(" start %f end %f t_start %d:%02d t_end %d:%02d pt %d\n", mbar_to_PSI(list->start), mbar_to_PSI(list->end), - FRACTION(list->t_start, 60), - FRACTION(list->t_end, 60), + FRACTION_TUPLE(list->t_start, 60), + FRACTION_TUPLE(list->t_end, 60), list->pressure_time); list = list->next; } diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp index 634e6c015..e2ed5eb99 100644 --- a/core/libdivecomputer.cpp +++ b/core/libdivecomputer.cpp @@ -441,7 +441,7 @@ sample_cb(dc_sample_type_t type, const dc_sample_value_t *pvalue, void *userdata break; #ifdef DEBUG_DC_VENDOR case DC_SAMPLE_VENDOR: - printf(" ", FRACTION(sample->time.seconds, 60), + printf(" ", FRACTION_TUPLE(sample->time.seconds, 60), value.vendor.type, value.vendor.size); for (int i = 0; i < value.vendor.size; ++i) printf("%02X", ((unsigned char *)value.vendor.data)[i]); diff --git a/core/membuffer.cpp b/core/membuffer.cpp index bba68d7b3..e950f6d58 100644 --- a/core/membuffer.cpp +++ b/core/membuffer.cpp @@ -219,7 +219,7 @@ void put_depth(struct membuffer *b, depth_t depth, const char *pre, const char * void put_duration(struct membuffer *b, duration_t duration, const char *pre, const char *post) { if (duration.seconds) - put_format(b, "%s%u:%02u%s", pre, FRACTION(duration.seconds, 60), post); + put_format(b, "%s%u:%02u%s", pre, FRACTION_TUPLE(duration.seconds, 60), post); } void put_pressure(struct membuffer *b, pressure_t pressure, const char *pre, const char *post) @@ -243,7 +243,7 @@ void put_degrees(struct membuffer *b, degrees_t value, const char *pre, const ch udeg = -udeg; sign = "-"; } - put_format(b, "%s%s%u.%06u%s", pre, sign, FRACTION(udeg, 1000000), post); + put_format(b, "%s%s%u.%06u%s", pre, sign, FRACTION_TUPLE(udeg, 1000000), post); } void put_location(struct membuffer *b, const location_t *loc, const char *pre, const char *post) diff --git a/core/planner.cpp b/core/planner.cpp index 902fb560e..b33c97624 100644 --- a/core/planner.cpp +++ b/core/planner.cpp @@ -59,7 +59,7 @@ extern "C" void dump_plan(struct diveplan *diveplan) diveplan->surface_pressure); dp = diveplan->dp; while (dp) { - printf("\t%3u:%02u: %6dmm cylid: %2d setpoint: %d\n", FRACTION(dp->time, 60), dp->depth, dp->cylinderid, dp->setpoint); + printf("\t%3u:%02u: %6dmm cylid: %2d setpoint: %d\n", FRACTION_TUPLE(dp->time, 60), dp->depth, dp->cylinderid, dp->setpoint); dp = dp->next; } } diff --git a/core/plannernotes.cpp b/core/plannernotes.cpp index 3848249f2..72ee910f0 100644 --- a/core/plannernotes.cpp +++ b/core/plannernotes.cpp @@ -156,7 +156,7 @@ extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, translate("gettextFromC", "Subsurface"), subsurface_canonical_version(), translate("gettextFromC", "dive plan (surface interval "), - FRACTION(diveplan->surface_interval / 60, 60), + FRACTION_TUPLE(diveplan->surface_interval / 60, 60), translate("gettextFromC", "created on"), get_current_date().c_str()); } @@ -234,16 +234,16 @@ extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, buf += casprintf_loc(translate("gettextFromC", "%s to %.*f %s in %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"), dp->depth.mm < lastprintdepth ? translate("gettextFromC", "Ascend") : translate("gettextFromC", "Descend"), decimals, depthvalue, depth_unit, - FRACTION(dp->time - lasttime, 60), - FRACTION(dp->time, 60), + FRACTION_TUPLE(dp->time - lasttime, 60), + FRACTION_TUPLE(dp->time, 60), gasname(gasmix), (double) dp->setpoint / 1000.0); } else { buf += casprintf_loc(translate("gettextFromC", "%s to %.*f %s in %d:%02d min - runtime %d:%02u on %s"), dp->depth.mm < lastprintdepth ? translate("gettextFromC", "Ascend") : translate("gettextFromC", "Descend"), decimals, depthvalue, depth_unit, - FRACTION(dp->time - lasttime, 60), - FRACTION(dp->time, 60), + FRACTION_TUPLE(dp->time - lasttime, 60), + FRACTION_TUPLE(dp->time, 60), gasname(gasmix)); } @@ -256,15 +256,15 @@ extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, if (dp->setpoint) { buf += casprintf_loc(translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar CCR)"), decimals, depthvalue, depth_unit, - FRACTION(dp->time - lasttime, 60), - FRACTION(dp->time, 60), + FRACTION_TUPLE(dp->time - lasttime, 60), + FRACTION_TUPLE(dp->time, 60), gasname(gasmix), (double) dp->setpoint / 1000.0); } else { buf += casprintf_loc(translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s %s"), decimals, depthvalue, depth_unit, - FRACTION(dp->time - lasttime, 60), - FRACTION(dp->time, 60), + FRACTION_TUPLE(dp->time - lasttime, 60), + FRACTION_TUPLE(dp->time, 60), gasname(gasmix), translate("gettextFromC", divemode_text_ui[dp->divemode])); } @@ -594,7 +594,7 @@ extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, buf += "
\n"; o2warning_exist = true; temp = casprintf_loc(translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), - pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); + pressures.o2, FRACTION_TUPLE(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); buf += format_string_std("%s %s
\n", translate("gettextFromC", "Warning:"), temp.c_str()); } else if (pressures.o2 < 0.16) { const char *depth_unit; @@ -604,7 +604,7 @@ extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, buf += "
"; o2warning_exist = true; temp = casprintf_loc(translate("gettextFromC", "low pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), - pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); + pressures.o2, FRACTION_TUPLE(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); buf += format_string_std("%s %s
\n", translate("gettextFromC", "Warning:"), temp.c_str()); } } diff --git a/core/profile.cpp b/core/profile.cpp index 36bbc842d..992434937 100644 --- a/core/profile.cpp +++ b/core/profile.cpp @@ -1368,7 +1368,7 @@ static std::vector plot_string(const struct dive *d, const struct p std::vector res; depthvalue = get_depth_units(entry->depth, NULL, &depth_unit); - res.push_back(casprintf_loc(translate("gettextFromC", "@: %d:%02d"), FRACTION(entry->sec, 60))); + res.push_back(casprintf_loc(translate("gettextFromC", "@: %d:%02d"), FRACTION_TUPLE(entry->sec, 60))); res.push_back(casprintf_loc(translate("gettextFromC", "D: %.1f%s"), depthvalue, depth_unit)); for (cyl = 0; cyl < pi->nr_cylinders; cyl++) { int mbar = get_plot_pressure(pi, idx, cyl); diff --git a/core/save-git.cpp b/core/save-git.cpp index 05ced734d..ff838dda5 100644 --- a/core/save-git.cpp +++ b/core/save-git.cpp @@ -135,9 +135,9 @@ static void put_gasmix(struct membuffer *b, struct gasmix mix) int he = mix.he.permille; if (o2) { - put_format(b, " o2=%u.%u%%", FRACTION(o2, 10)); + put_format(b, " o2=%u.%u%%", FRACTION_TUPLE(o2, 10)); if (he) - put_format(b, " he=%u.%u%%", FRACTION(he, 10)); + put_format(b, " he=%u.%u%%", FRACTION_TUPLE(he, 10)); } } @@ -251,7 +251,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl { int idx; - put_format(b, "%3u:%02u", FRACTION(sample->time.seconds, 60)); + put_format(b, "%3u:%02u", FRACTION_TUPLE(sample->time.seconds, 60)); put_milli(b, " ", sample->depth.mm, "m"); put_temperature(b, sample->temperature, " ", "°C"); @@ -293,11 +293,11 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl /* the deco/ndl values are stored whenever they change */ if (sample->ndl.seconds != old->ndl.seconds) { - put_format(b, " ndl=%u:%02u", FRACTION(sample->ndl.seconds, 60)); + put_format(b, " ndl=%u:%02u", FRACTION_TUPLE(sample->ndl.seconds, 60)); old->ndl = sample->ndl; } if (sample->tts.seconds != old->tts.seconds) { - put_format(b, " tts=%u:%02u", FRACTION(sample->tts.seconds, 60)); + put_format(b, " tts=%u:%02u", FRACTION_TUPLE(sample->tts.seconds, 60)); old->tts = sample->tts; } if (sample->in_deco != old->in_deco) { @@ -305,7 +305,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl old->in_deco = sample->in_deco; } if (sample->stoptime.seconds != old->stoptime.seconds) { - put_format(b, " stoptime=%u:%02u", FRACTION(sample->stoptime.seconds, 60)); + put_format(b, " stoptime=%u:%02u", FRACTION_TUPLE(sample->stoptime.seconds, 60)); old->stoptime = sample->stoptime; } @@ -320,7 +320,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl } if (sample->rbt.seconds != old->rbt.seconds) { - put_format(b, " rbt=%u:%02u", FRACTION(sample->rbt.seconds, 60)); + put_format(b, " rbt=%u:%02u", FRACTION_TUPLE(sample->rbt.seconds, 60)); old->rbt.seconds = sample->rbt.seconds; } @@ -393,7 +393,7 @@ static void save_samples(struct membuffer *b, struct dive *dive, struct divecomp static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev) { - put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60)); + put_format(b, "event %d:%02d", FRACTION_TUPLE(ev->time.seconds, 60)); show_index(b, ev->type, "type=", ""); show_index(b, ev->flags, "flags=", ""); @@ -456,7 +456,7 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b) { pressure_t surface_pressure = un_fixup_surface_pressure(dive); if (dive->dc.duration.seconds > 0) - put_format(b, "duration %u:%02u min\n", FRACTION(dive->dc.duration.seconds, 60)); + put_format(b, "duration %u:%02u min\n", FRACTION_TUPLE(dive->dc.duration.seconds, 60)); SAVE("rating", rating); SAVE("visibility", visibility); SAVE("wavesize", wavesize); @@ -653,7 +653,7 @@ static int save_one_picture(git_repository *repo, struct dir *dir, struct pictur h = offset / 3600; offset -= h *3600; return blob_insert(repo, dir, &buf, "%c%02u=%02u=%02u", - sign, h, FRACTION(offset, 60)); + sign, h, FRACTION_TUPLE(offset, 60)); } static int save_pictures(git_repository *repo, struct dir *dir, struct dive *dive) diff --git a/core/save-html.cpp b/core/save-html.cpp index b693df9b6..cb1c785e6 100644 --- a/core/save-html.cpp +++ b/core/save-html.cpp @@ -163,8 +163,8 @@ static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) } if (cylinder->gasmix.o2.permille) { - put_format(b, "\"O2\":\"%u.%u%%\",", FRACTION(cylinder->gasmix.o2.permille, 10)); - put_format(b, "\"He\":\"%u.%u%%\"", FRACTION(cylinder->gasmix.he.permille, 10)); + put_format(b, "\"O2\":\"%u.%u%%\",", FRACTION_TUPLE(cylinder->gasmix.o2.permille, 10)); + put_format(b, "\"He\":\"%u.%u%%\"", FRACTION_TUPLE(cylinder->gasmix.he.permille, 10)); } else { write_attribute(b, "O2", "Air", ""); } @@ -364,7 +364,7 @@ static void write_one_dive(struct membuffer *b, struct dive *dive, const char *p put_format(b, "\"surge\":%d,", dive->surge); put_format(b, "\"chill\":%d,", dive->chill); put_format(b, "\"dive_duration\":\"%u:%02u min\",", - FRACTION(dive->duration.seconds, 60)); + FRACTION_TUPLE(dive->duration.seconds, 60)); put_string(b, "\"temperature\":{"); put_HTML_airtemp(b, dive, "\"air\":\"", "\","); put_HTML_watertemp(b, dive, "\"water\":\"", "\""); diff --git a/core/save-profiledata.c b/core/save-profiledata.c index 56426b3ec..fa83e5bb1 100644 --- a/core/save-profiledata.c +++ b/core/save-profiledata.c @@ -179,7 +179,7 @@ static void put_st_event(struct membuffer *b, struct plot_data *entry, int offse put_video_time(b, entry->sec - offset); put_video_time(b, (entry+1)->sec - offset < length ? (entry+1)->sec - offset : length); put_format(b, "Default,,0,0,0,,"); - put_format(b, "%d:%02d ", FRACTION(entry->sec, 60)); + put_format(b, "%d:%02d ", FRACTION_TUPLE(entry->sec, 60)); value = get_depth_units(entry->depth, &decimals, &unit); put_format(b, "D=%02.2f %s ", value, unit); if (entry->temperature) { @@ -189,10 +189,10 @@ static void put_st_event(struct membuffer *b, struct plot_data *entry, int offse // Only show NDL if it is not essentially infinite, show TTS for mandatory stops. if (entry->ndl_calc < 3600) { if (entry->ndl_calc > 0) - put_format(b, "NDL=%d:%02d ", FRACTION(entry->ndl_calc, 60)); + put_format(b, "NDL=%d:%02d ", FRACTION_TUPLE(entry->ndl_calc, 60)); else if (entry->tts_calc > 0) - put_format(b, "TTS=%d:%02d ", FRACTION(entry->tts_calc, 60)); + put_format(b, "TTS=%d:%02d ", FRACTION_TUPLE(entry->tts_calc, 60)); } if (entry->surface_gf > 0.0) { put_format(b, "sGF=%.1f%% ", entry->surface_gf); diff --git a/core/save-xml.cpp b/core/save-xml.cpp index e053db15c..21ed7e089 100644 --- a/core/save-xml.cpp +++ b/core/save-xml.cpp @@ -169,9 +169,9 @@ static void put_gasmix(struct membuffer *b, struct gasmix mix) int he = mix.he.permille; if (o2) { - put_format(b, " o2='%u.%u%%'", FRACTION(o2, 10)); + put_format(b, " o2='%u.%u%%'", FRACTION_TUPLE(o2, 10)); if (he) - put_format(b, " he='%u.%u%%'", FRACTION(he, 10)); + put_format(b, " he='%u.%u%%'", FRACTION_TUPLE(he, 10)); } } @@ -236,7 +236,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl { int idx; - put_format(b, " time.seconds, 60)); + put_format(b, " time.seconds, 60)); put_milli(b, " depth='", sample->depth.mm, " m'"); if (sample->temperature.mkelvin && sample->temperature.mkelvin != old->temperature.mkelvin) { put_temperature(b, sample->temperature, " temp='", " C'"); @@ -278,15 +278,15 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl /* the deco/ndl values are stored whenever they change */ if (sample->ndl.seconds != old->ndl.seconds) { - put_format(b, " ndl='%u:%02u min'", FRACTION(sample->ndl.seconds, 60)); + put_format(b, " ndl='%u:%02u min'", FRACTION_TUPLE(sample->ndl.seconds, 60)); old->ndl = sample->ndl; } if (sample->tts.seconds != old->tts.seconds) { - put_format(b, " tts='%u:%02u min'", FRACTION(sample->tts.seconds, 60)); + put_format(b, " tts='%u:%02u min'", FRACTION_TUPLE(sample->tts.seconds, 60)); old->tts = sample->tts; } if (sample->rbt.seconds != old->rbt.seconds) { - put_format(b, " rbt='%u:%02u min'", FRACTION(sample->rbt.seconds, 60)); + put_format(b, " rbt='%u:%02u min'", FRACTION_TUPLE(sample->rbt.seconds, 60)); old->rbt = sample->rbt; } if (sample->in_deco != old->in_deco) { @@ -294,7 +294,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl old->in_deco = sample->in_deco; } if (sample->stoptime.seconds != old->stoptime.seconds) { - put_format(b, " stoptime='%u:%02u min'", FRACTION(sample->stoptime.seconds, 60)); + put_format(b, " stoptime='%u:%02u min'", FRACTION_TUPLE(sample->stoptime.seconds, 60)); old->stoptime = sample->stoptime; } @@ -355,7 +355,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev) { - put_format(b, " time.seconds, 60)); + put_format(b, " time.seconds, 60)); show_index(b, ev->type, "type='", "'"); show_index(b, ev->flags, "flags='", "'"); if (!strcmp(ev->name,"modechange")) @@ -490,7 +490,7 @@ static void save_picture(struct membuffer *b, struct picture *pic) sign = '-'; offset = -offset; } - put_format(b, " offset='%c%u:%02u min'", sign, FRACTION(offset, 60)); + put_format(b, " offset='%c%u:%02u min'", sign, FRACTION_TUPLE(offset, 60)); } put_location(b, &pic->location, " gps='","'"); @@ -525,7 +525,7 @@ extern "C" void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool // These three are calculated, and not read when loading. // But saving them into the XML is useful for data export. if (dive->sac > 100) - put_format(b, " sac='%d.%03d l/min'", FRACTION(dive->sac, 1000)); + put_format(b, " sac='%d.%03d l/min'", FRACTION_TUPLE(dive->sac, 1000)); if (dive->otu) put_format(b, " otu='%d'", dive->otu); if (dive->maxcns) @@ -541,7 +541,7 @@ extern "C" void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool put_pressure(b, surface_pressure, " airpressure='", " bar'"); if (dive->dc.duration.seconds > 0) put_format(b, " duration='%u:%02u min'>\n", - FRACTION(dive->dc.duration.seconds, 60)); + FRACTION_TUPLE(dive->dc.duration.seconds, 60)); else put_format(b, ">\n"); save_overview(b, dive, anonymize); diff --git a/core/string-format.cpp b/core/string-format.cpp index 8bf32fbab..4e10c38bf 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -302,7 +302,7 @@ QString formatDayOfWeek(int day) QString formatMinutes(int seconds) { - return QString::asprintf("%d:%.2d", FRACTION(seconds, 60)); + return QString::asprintf("%d:%.2d", FRACTION_TUPLE(seconds, 60)); } QString formatTripTitle(const dive_trip *trip) diff --git a/core/uemis.c b/core/uemis.c index 967a56d71..b5d6d006c 100644 --- a/core/uemis.c +++ b/core/uemis.c @@ -380,11 +380,11 @@ void uemis_parse_divelog_binary(char *base64, void *datap) add_extra_data(dc, "Serial", buffer); snprintf(buffer, sizeof(buffer), "%d", *(uint16_t *)(data + i + 35)); add_extra_data(dc, "main battery after dive", buffer); - snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION(*(uint16_t *)(data + i + 24), 60)); + snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data + i + 24), 60)); add_extra_data(dc, "no fly time", buffer); - snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION(*(uint16_t *)(data + i + 26), 60)); + snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data + i + 26), 60)); add_extra_data(dc, "no dive time", buffer); - snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION(*(uint16_t *)(data + i + 28), 60)); + snprintf(buffer, sizeof(buffer), "%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data + i + 28), 60)); add_extra_data(dc, "desat time", buffer); snprintf(buffer, sizeof(buffer), "%u", *(uint16_t *)(data + i + 30)); add_extra_data(dc, "allowed altitude", buffer); diff --git a/core/units.h b/core/units.h index 806649ba2..c18f6f414 100644 --- a/core/units.h +++ b/core/units.h @@ -13,8 +13,8 @@ extern "C" { #include #endif -#define FRACTION(n, x) ((unsigned)(n) / (x)), ((unsigned)(n) % (x)) -#define SIGNED_FRAC(n, x) ((n) >= 0 ? '+': '-'), ((n) >= 0 ? (unsigned)(n) / (x) : (-(n) / (x))), ((unsigned)((n) >= 0 ? (n) : -(n)) % (x)) +#define FRACTION_TUPLE(n, x) ((unsigned)(n) / (x)), ((unsigned)(n) % (x)) +#define SIGNED_FRAC_TRIPLET(n, x) ((n) >= 0 ? '+': '-'), ((n) >= 0 ? (unsigned)(n) / (x) : (-(n) / (x))), ((unsigned)((n) >= 0 ? (n) : -(n)) % (x)) #define O2_IN_AIR 209 // permille #define N2_IN_AIR 781 diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 1867bbd74..6c16eae9c 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1177,7 +1177,7 @@ int DivePlannerPointsModel::analyzeVariations(struct decostop *min, struct decos rightsum = maxsum - midsum; #ifdef DEBUG_STOPVAR - printf("Total + %d:%02d/%s +- %d s/%s\n\n", FRACTION((leftsum + rightsum) / 2, 60), unit, + printf("Total + %d:%02d/%s +- %d s/%s\n\n", FRACTION_TUPLE((leftsum + rightsum) / 2, 60), unit, (rightsum - leftsum) / 2, unit); #else Q_UNUSED(unit) @@ -1266,8 +1266,8 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c char buf[200]; sprintf(buf, ", %s: %c %d:%02d /%s %c %d:%02d /min", qPrintable(tr("Stop times")), - SIGNED_FRAC(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units), - SIGNED_FRAC(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60)); + SIGNED_FRAC_TRIPLET(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units), + SIGNED_FRAC_TRIPLET(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60)); // By using a signal, we can transport the variations to the main thread. emit variationsComputed(QString(buf));