From d89ef3d90643086c187c7714fa9ead4e3915e35e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 1 Jan 2022 22:22:40 +0100 Subject: [PATCH] cleanup: fix narrowing type conversion warning In pscr_o2() the result of a double calculation was implicitly converted to int, which resulted in a gcc warning. Part of the expression was explicitly converted to int, but then subtracted from a double. Instead, do all the calculations in double and cast the final expression to int. This is probably the prudent thing to do. Signed-off-by: Berthold Stoeger --- core/gas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/gas.c b/core/gas.c index 1e74dccfc..175e1a7d8 100644 --- a/core/gas.c +++ b/core/gas.c @@ -98,8 +98,10 @@ fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_component comp // O2 pressure in mbar according to the steady state model for the PSCR // NB: Ambient pressure comes in bar! -int pscr_o2(const double amb_pressure, struct gasmix mix) { - int o2 = get_o2(mix) * amb_pressure - (int)((1.0 - get_o2(mix) / 1000.0) * prefs.o2consumption / (prefs.bottomsac * prefs.pscr_ratio) * 1000000); +int pscr_o2(const double amb_pressure, struct gasmix mix) +{ + int o2 = (int)(get_o2(mix) * amb_pressure - + (1.0 - get_o2(mix) / 1000.0) * prefs.o2consumption / (prefs.bottomsac * prefs.pscr_ratio) * 1000000); if (o2 < 0.0) // He's dead, Jim. o2 = 0.0; return o2;