Fix undefined behaviour in modulo360f (#13976)

Resolves a crash on macOS/arm64 by no longer depending on UB.
This commit is contained in:
superfloh247 2023-11-12 20:08:33 +01:00 committed by GitHub
parent 2bc0d76f63
commit 7cb20dd6c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 21 deletions

View File

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irr_aabb3d.h"
#include "SColor.h"
#include <matrix4.h>
#include <cmath>
#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);
}