From 7cb20dd6c28794d5651ee835cca067ebbdfbcf5b Mon Sep 17 00:00:00 2001 From: superfloh247 Date: Sun, 12 Nov 2023 20:08:33 +0100 Subject: [PATCH] Fix undefined behaviour in modulo360f (#13976) Resolves a crash on macOS/arm64 by no longer depending on UB. --- src/util/numeric.h | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/util/numeric.h b/src/util/numeric.h index 4863f805b..d67dd0f5f 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_aabb3d.h" #include "SColor.h" #include +#include #define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d))) #define myfloor(x) ((x) < 0.0 ? (int)(x) - 1 : (int)(x)) @@ -195,30 +196,10 @@ struct MeshGrid { * * \note This is also used in cases where degrees wrapped to the range [0, 360] * is innapropriate (e.g. pitch needs negative values) - * - * \internal functionally equivalent -- although precision may vary slightly -- - * to fmodf((f), 360.0f) however empirical tests indicate that this approach is - * faster. */ inline float modulo360f(float f) { - int sign; - int whole; - float fraction; - - if (f < 0) { - f = -f; - sign = -1; - } else { - sign = 1; - } - - whole = f; - - fraction = f - whole; - whole %= 360; - - return sign * (whole + fraction); + return fmodf(f, 360.0f); }