summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-02-24 02:37:04 +0100
committerGitHub <noreply@github.com>2019-02-24 02:37:04 +0100
commit4ebb544ffacdbf0c3fc190bdfe1448a26e05782c (patch)
tree5735fcce0dc292f899404aa28a35693b76f576aa
parentef61c14dda30a6923b587d516344bbdca6983660 (diff)
parent18b90508a115661b9beba32fad372cd60a1ae0cd (diff)
Merge pull request #26171 from Calinou/fix-wrapi-crash
Fix crash when using `wrapi()` with a range of zero
-rw-r--r--core/math/math_funcs.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 629002ced6..f8f5ddfeaa 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -219,15 +219,15 @@ public:
static _ALWAYS_INLINE_ int wrapi(int value, int min, int max) {
int rng = max - min;
- return min + ((((value - min) % rng) + rng) % rng);
+ return (rng != 0) ? min + ((((value - min) % rng) + rng) % rng) : min;
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
double rng = max - min;
- return value - (rng * Math::floor((value - min) / rng));
+ return (!is_equal_approx(rng, 0.0)) ? value - (rng * Math::floor((value - min) / rng)) : min;
}
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
float rng = max - min;
- return value - (rng * Math::floor((value - min) / rng));
+ return (!is_equal_approx(rng, 0.0f)) ? value - (rng * Math::floor((value - min) / rng)) : min;
}
// double only, as these functions are mainly used by the editor and not performance-critical,