From 2a28ee7f3d633ba73cba7c0d03d084e773ed3135 Mon Sep 17 00:00:00 2001 From: Paul Koch Date: Wed, 15 Jan 2025 01:50:48 -0800 Subject: [PATCH] disable non-IEEE 754 math --- build.sh | 2 +- shared/libebm/interpretable_numerics.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index dc43b8646..36989946f 100644 --- a/build.sh +++ b/build.sh @@ -413,7 +413,7 @@ all_args="$all_args -Wformat=2" all_args="$all_args -Wno-format-nonliteral" all_args="$all_args -Wno-parentheses" all_args="$all_args -fvisibility=hidden -fvisibility-inlines-hidden" -all_args="$all_args -fno-math-errno -fno-trapping-math" +all_args="$all_args -fno-math-errno -fno-trapping-math -fno-fast-math -ffp-contract=off" # TODO: once we have highly efficient tightly looped code, try no -fpic and see if that makes better code. The compiler can save a register in this case. See https://akkadia.org/drepper/dsohowto.pdf # TODO: check no-plt compiler option all_args="$all_args -fpic" diff --git a/shared/libebm/interpretable_numerics.cpp b/shared/libebm/interpretable_numerics.cpp index 947a0ad5e..29383a480 100644 --- a/shared/libebm/interpretable_numerics.cpp +++ b/shared/libebm/interpretable_numerics.cpp @@ -1379,6 +1379,9 @@ static double Mean(const size_t cSamples, // https://stackoverflow.com/questions/895929/how-do-i-determine-the-standard-deviation-stddev-of-a-set-of-values // https://www.johndcook.com/blog/standard_deviation/ + // do not put multiple floating point operations in the same statement since that can be optimized + // https://clang.llvm.org/docs/UsersManual.html + double factor = 1.0; double mean; size_t cNaN; @@ -1440,7 +1443,8 @@ static double Mean(const size_t cSamples, // if all the weights are zero, then weigh them all equally ratio = double{1} / static_cast(cNormal); } - mean += numerator * ratio; + const double multiple = numerator * ratio; + mean += multiple; } if(nullptr != pWeight) { ++pWeight;