summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-06-15 15:27:57 +0200
committerGitHub <noreply@github.com>2022-06-15 15:27:57 +0200
commitcc6b2f42878656933e7ec2b7a3ad2c5126d56c55 (patch)
tree3e5d0ed9f1d71e6496592a071077d732248a5481
parent67156aa4c24d20a28be0888399769272c671f5a8 (diff)
parent09418afbc0b5a5642448786751b590352ee6cf97 (diff)
Merge pull request #61812 from Chaosus/fix_wrapf
-rw-r--r--core/math/math_funcs.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 068bc0397e..c8a55341aa 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -302,11 +302,19 @@ public:
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
double range = max - min;
- return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ double result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ if (is_equal_approx(result, max)) {
+ return min;
+ }
+ return result;
}
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
float range = max - min;
- return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ float result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ if (is_equal_approx(result, max)) {
+ return min;
+ }
+ return result;
}
static _ALWAYS_INLINE_ float fract(float value) {