summaryrefslogtreecommitdiffstats
path: root/tests/core/math
diff options
context:
space:
mode:
authorlawnjelly <lawnjelly@gmail.com>2023-05-09 13:49:26 +0100
committerlawnjelly <lawnjelly@gmail.com>2023-05-11 08:34:34 +0100
commit50c5ed4876250f785be54b8f6124e7663afa38dc (patch)
tree33b998adda461dd8d62e11f8bde2463f396de795 /tests/core/math
parent769d8a7bbe6f59a8a7cae0194b65bf078c9bb2b4 (diff)
downloadredot-engine-50c5ed4876250f785be54b8f6124e7663afa38dc.tar.gz
Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input. The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
Diffstat (limited to 'tests/core/math')
-rw-r--r--tests/core/math/test_math_funcs.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h
index 3e587390f8..da96ace63f 100644
--- a/tests/core/math/test_math_funcs.h
+++ b/tests/core/math/test_math_funcs.h
@@ -157,15 +157,15 @@ TEST_CASE_TEMPLATE("[Math] asin/acos/atan", T, float, double) {
CHECK(Math::asin((T)0.1) == doctest::Approx((T)0.1001674212));
CHECK(Math::asin((T)0.5) == doctest::Approx((T)0.5235987756));
CHECK(Math::asin((T)1.0) == doctest::Approx((T)1.5707963268));
- CHECK(Math::is_nan(Math::asin((T)1.5)));
- CHECK(Math::is_nan(Math::asin((T)450.0)));
+ CHECK(Math::asin((T)2.0) == doctest::Approx((T)1.5707963268));
+ CHECK(Math::asin((T)-2.0) == doctest::Approx((T)-1.5707963268));
CHECK(Math::acos((T)-0.1) == doctest::Approx((T)1.670963748));
CHECK(Math::acos((T)0.1) == doctest::Approx((T)1.4706289056));
CHECK(Math::acos((T)0.5) == doctest::Approx((T)1.0471975512));
CHECK(Math::acos((T)1.0) == doctest::Approx((T)0.0));
- CHECK(Math::is_nan(Math::acos((T)1.5)));
- CHECK(Math::is_nan(Math::acos((T)450.0)));
+ CHECK(Math::acos((T)2.0) == doctest::Approx((T)0.0));
+ CHECK(Math::acos((T)-2.0) == doctest::Approx((T)Math_PI));
CHECK(Math::atan((T)-0.1) == doctest::Approx((T)-0.0996686525));
CHECK(Math::atan((T)0.1) == doctest::Approx((T)0.0996686525));