diff options
author | Jcrespo <jcrespo@wikimedia.org> | 2023-06-18 14:47:01 +0200 |
---|---|---|
committer | Jaime Crespo <jcrespo@wikimedia.org> | 2023-09-01 01:27:56 +0200 |
commit | 528a76486c5475bdbb5cc9d1152d349205a366f6 (patch) | |
tree | 72977a33dd2770ab21c2da28c42e890100f42089 /tests | |
parent | 549fcce5f8f7beace3e5c90e9bbe4335d4fd1476 (diff) | |
download | redot-engine-528a76486c5475bdbb5cc9d1152d349205a366f6.tar.gz |
Add inverse hyperbolic functions `asinh()`, `acosh()` & `atanh()`
GDScript has the following built-in trigonometry functions:
- `sin()`
- `cos()`
- `tan()`
- `asin()`
- `acos()`
- `atan()`
- `atan()`
- `sinh()`
- `cosh()`
- `tanh()`
However, it lacks the hyperbolic arc (also known as inverse
hyperbolic) functions:
- `asinh()`
- `acosh()`
- `atanh()`
Implement them by just exposing the C++ Math library, but clamping
its values to the closest real defined value.
For the cosine, clamp input values lower than 1 to 1.
In the case of the tangent, where the limit value is infinite,
clamp it to -inf or +inf.
References #78377
Fixes godotengine/godot-proposals#7110
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/math/test_math_funcs.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h index b6cb9620f1..e3504ef1e5 100644 --- a/tests/core/math/test_math_funcs.h +++ b/tests/core/math/test_math_funcs.h @@ -175,6 +175,37 @@ TEST_CASE_TEMPLATE("[Math] asin/acos/atan", T, float, double) { CHECK(Math::atan((T)450.0) == doctest::Approx((T)1.5685741082)); } +TEST_CASE_TEMPLATE("[Math] asinh/acosh/atanh", T, float, double) { + CHECK(Math::asinh((T)-2.0) == doctest::Approx((T)-1.4436354751)); + CHECK(Math::asinh((T)-0.1) == doctest::Approx((T)-0.0998340788)); + CHECK(Math::asinh((T)0.1) == doctest::Approx((T)0.0998340788)); + CHECK(Math::asinh((T)0.5) == doctest::Approx((T)0.4812118250)); + CHECK(Math::asinh((T)1.0) == doctest::Approx((T)0.8813735870)); + CHECK(Math::asinh((T)2.0) == doctest::Approx((T)1.4436354751)); + + CHECK(Math::acosh((T)-2.0) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)-0.1) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)0.1) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)0.5) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)1.0) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)2.0) == doctest::Approx((T)1.3169578969)); + CHECK(Math::acosh((T)450.0) == doctest::Approx((T)6.8023935287)); + + CHECK(Math::is_inf(Math::atanh((T)-2.0))); + CHECK(Math::atanh((T)-2.0) < (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)-1.0))); + CHECK(Math::atanh((T)-1.0) < (T)0.0); + CHECK(Math::atanh((T)-0.1) == doctest::Approx((T)-0.1003353477)); + CHECK(Math::atanh((T)0.1) == doctest::Approx((T)0.1003353477)); + CHECK(Math::atanh((T)0.5) == doctest::Approx((T)0.5493061443)); + CHECK(Math::is_inf(Math::atanh((T)1.0))); + CHECK(Math::atanh((T)1.0) > (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)1.5))); + CHECK(Math::atanh((T)1.5) > (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)450.0))); + CHECK(Math::atanh((T)450.0) > (T)0.0); +} + TEST_CASE_TEMPLATE("[Math] sinc/sincn/atan2", T, float, double) { CHECK(Math::sinc((T)-0.1) == doctest::Approx((T)0.9983341665)); CHECK(Math::sinc((T)0.1) == doctest::Approx((T)0.9983341665)); |