Skip to content

Commit

Permalink
Merge pull request #70812 from Chaosus/wrapf_optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus authored Jan 2, 2023
2 parents 5726770 + b28571c commit b29bb11
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,21 @@ class Math {
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
double range = max - min;
double result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
if (is_zero_approx(range)) {
return min;
}
double result = 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;
float result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
if (is_zero_approx(range)) {
return min;
}
float result = value - (range * Math::floor((value - min) / range));
if (is_equal_approx(result, max)) {
return min;
}
Expand Down

0 comments on commit b29bb11

Please sign in to comment.