mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
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:
parent
9ea5a00e24
commit
dfbdd035da
2 changed files with 9 additions and 1 deletions
|
@ -250,7 +250,7 @@ constexpr T acos(T value)
|
||||||
CONSTEXPR_STATE(acos, value);
|
CONSTEXPR_STATE(acos, value);
|
||||||
|
|
||||||
// FIXME: I am naive
|
// FIXME: I am naive
|
||||||
return Pi<T> + asin(value);
|
return static_cast<T>(0.5) * Pi<T> - asin<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<FloatingPoint T>
|
template<FloatingPoint T>
|
||||||
|
|
|
@ -259,3 +259,11 @@ TEST_CASE(fmax_and_fmin)
|
||||||
EXPECT(fmin(0, NAN) == 0);
|
EXPECT(fmin(0, NAN) == 0);
|
||||||
EXPECT(isnan(fmin(NAN, NAN)));
|
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)));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue