From 2a966ac2a9a807f4ae45d671cca8b245f8f70ece Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 7 Aug 2019 22:28:31 +0200 Subject: Cleanup: replace macro by inline function in gas-model.c Replace a macro calculating a degree-three polynomial by an inline function. Moreover, calculate the powers 1, 2 and 3 of the pressure inside the function. The compiler will be smart enough to optimize this to the same code. The only important thing is to write "x*x*x*coeff" instead of "coeff*x*x*x". The compiler can't optimize the latter because ... wonderful floating point semantics. Signed-off-by: Berthold Stoeger --- core/gas-model.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/gas-model.c b/core/gas-model.c index 4dccdf6b3..44c64864a 100644 --- a/core/gas-model.c +++ b/core/gas-model.c @@ -6,7 +6,10 @@ #include "dive.h" /* "Virial minus one" - the virial cubic form without the initial 1.0 */ -#define virial_m1(C, x1, x2, x3) (C[0]*x1+C[1]*x2+C[2]*x3) +static double virial_m1(const double coeff[], double x) +{ + return x*coeff[0] + x*x*coeff[1] + x*x*x*coeff[2]; +} /* * Z = pV/nRT @@ -44,7 +47,6 @@ double gas_compressibility_factor(struct gasmix gas, double bar) +5.33304543646e-11 }; int o2, he; - double x1, x2, x3; double Z; /* @@ -58,11 +60,9 @@ double gas_compressibility_factor(struct gasmix gas, double bar) o2 = get_o2(gas); he = get_he(gas); - x1 = bar; x2 = x1*x1; x3 = x2*x1; - - Z = virial_m1(o2_coefficients, x1, x2, x3) * o2 + - virial_m1(he_coefficients, x1, x2, x3) * he + - virial_m1(n2_coefficients, x1, x2, x3) * (1000 - o2 - he); + Z = virial_m1(o2_coefficients, bar) * o2 + + virial_m1(he_coefficients, bar) * he + + virial_m1(n2_coefficients, bar) * (1000 - o2 - he); /* * We add the 1.0 at the very end - the linear mixing of the -- cgit v1.2.3-70-g09d2