From fae68b7a684bdc320159360308e7d420d7f9dc92 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Mon, 7 Aug 2023 16:34:55 +0900 Subject: [PATCH] fix: merge_pressure does not calculate starting pressures correctly The existing logic correctly calculates the minimum (ie, ending) pressure, but not the maximum (ie starting) pressure. For example, 2 tanks A and B with manual pressures (same tank on subsequent dives, which were then merged): A: 205 - 84 B: 83 - 55 When merging the starting pressures, the call is : merge_pressure(205, 0, 83, 0, false) The final comparison is: if(false && 205 < 83) return 205; else return 83; -> So 83 is returned even though 205 should have been. Signed-off-by: Michael Werle --- core/dive.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/dive.c b/core/dive.c index ecba10444..a0399fb63 100644 --- a/core/dive.c +++ b/core/dive.c @@ -1852,10 +1852,9 @@ static pressure_t merge_pressures(pressure_t a, pressure_t sample_a, pressure_t a = b; if (!b.mbar) b = a; - if (take_min && a.mbar < b.mbar) - return a; - else - return b; + if (take_min) + return a.mbar < b.mbar? a : b; + return a.mbar > b.mbar? a : b; } /*