summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorYuri Rubinsky <chaosus89@gmail.com>2022-06-08 16:55:31 +0300
committerYuri Rubinsky <chaosus89@gmail.com>2022-06-08 17:11:55 +0300
commit09418afbc0b5a5642448786751b590352ee6cf97 (patch)
treebb0c8af7dfa9f8345234285d67b3d9ed1b7a0d46 /core/math
parentc09d830106a7b1e48d4cff6b818cb3979d3bde21 (diff)
Fix `wrapf` to correct wrap values with 0.1 stepping
Diffstat (limited to 'core/math')
-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) {