diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-09-03 12:00:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 12:00:56 +0200 |
commit | 40a9cc66a983611dbfac4c3b00964c730f9f3d15 (patch) | |
tree | 34b2d219a64ce0e7d3931278405d2889a0aeb644 /core/math | |
parent | 4c169352a61fc97eff65867017910c94a6dbfde3 (diff) | |
parent | f8b4cf0fc41b40601d90a44bd6d348a6c1e11fe5 (diff) |
Merge pull request #31871 from aaronfranke/equal-approx-inf
Check for exact equality before approximate equality
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/math_funcs.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index af845ca01e..9078abea68 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -300,6 +300,11 @@ public: } static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b) { + // Check for exact equality first, required to handle "infinity" values. + if (a == b) { + return true; + } + // Then check for approximate equality. real_t tolerance = CMP_EPSILON * abs(a); if (tolerance < CMP_EPSILON) { tolerance = CMP_EPSILON; @@ -308,6 +313,11 @@ public: } static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b, real_t tolerance) { + // Check for exact equality first, required to handle "infinity" values. + if (a == b) { + return true; + } + // Then check for approximate equality. return abs(a - b) < tolerance; } |