diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-07-05 00:35:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-05 00:35:46 +0200 |
commit | c538f2ff8014a3a411c5c3dd66de4ead6d341035 (patch) | |
tree | 5adb182e060bea91ef9fc891cfad9996dfdef070 /core | |
parent | 4f39d330cf1c6434988fffa5b01428d86d1e3d4c (diff) | |
parent | eebe41b1b0cbe10989ab2f7451ac5699c13c16a2 (diff) |
Merge pull request #19279 from aaronfranke/core-fposmod-fix
[Core] [Math] Fix fposmod() function
Diffstat (limited to 'core')
-rw-r--r-- | core/math/math_funcs.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 20001bb9a6..f0c0268f31 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -182,8 +182,22 @@ public: static _ALWAYS_INLINE_ float abs(float g) { return absf(g); } static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; } - static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) { return (p_x >= 0) ? Math::fmod(p_x, p_y) : p_y - Math::fmod(-p_x, p_y); } - static _ALWAYS_INLINE_ float fposmod(float p_x, float p_y) { return (p_x >= 0) ? Math::fmod(p_x, p_y) : p_y - Math::fmod(-p_x, p_y); } + static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) { + double value = Math::fmod(p_x, p_y); + if ((value < 0 && p_y > 0) || (value > 0 && p_y < 0)) { + value += p_y; + } + value += 0.0; + return value; + } + static _ALWAYS_INLINE_ float fposmod(float p_x, float p_y) { + float value = Math::fmod(p_x, p_y); + if ((value < 0 && p_y > 0) || (value > 0 && p_y < 0)) { + value += p_y; + } + value += 0.0; + return value; + } static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * Math_PI / 180.0; } |