forked from Mirrorlandia_minetest/minetest
Fix undefined behaviour in modulo360f (#13976)
Resolves a crash on macOS/arm64 by no longer depending on UB.
This commit is contained in:
parent
2bc0d76f63
commit
7cb20dd6c2
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irr_aabb3d.h"
|
#include "irr_aabb3d.h"
|
||||||
#include "SColor.h"
|
#include "SColor.h"
|
||||||
#include <matrix4.h>
|
#include <matrix4.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d)))
|
#define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d)))
|
||||||
#define myfloor(x) ((x) < 0.0 ? (int)(x) - 1 : (int)(x))
|
#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]
|
* \note This is also used in cases where degrees wrapped to the range [0, 360]
|
||||||
* is innapropriate (e.g. pitch needs negative values)
|
* 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)
|
inline float modulo360f(float f)
|
||||||
{
|
{
|
||||||
int sign;
|
return fmodf(f, 360.0f);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user