AK: Implement acos<T> correctly

This is a naive implementation based on the symmetry with `asin`.

Before, I'm not really sure what we were doing, but it was returning
wildly incorrect results.
This commit is contained in:
Jelle Raaijmakers 2021-11-18 16:16:57 +01:00 committed by Andreas Kling
parent 9ea5a00e24
commit dfbdd035da
Notes: sideshowbarker 2024-07-18 01:01:17 +09:00
2 changed files with 9 additions and 1 deletions

View File

@ -250,7 +250,7 @@ constexpr T acos(T value)
CONSTEXPR_STATE(acos, value);
// FIXME: I am naive
return Pi<T> + asin(value);
return static_cast<T>(0.5) * Pi<T> - asin<T>(value);
}
template<FloatingPoint T>

View File

@ -259,3 +259,11 @@ TEST_CASE(fmax_and_fmin)
EXPECT(fmin(0, NAN) == 0);
EXPECT(isnan(fmin(NAN, NAN)));
}
TEST_CASE(acos)
{
EXPECT_APPROXIMATE(acos(-1), M_PI);
EXPECT_APPROXIMATE(acos(0), 0.5 * M_PI);
EXPECT_APPROXIMATE(acos(1), 0);
EXPECT(isnan(acos(1.1)));
}