mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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
Notes:
sideshowbarker
2024-07-18 01:01:17 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/dfbdd035daf Pull-request: https://github.com/SerenityOS/serenity/pull/10958 Reviewed-by: https://github.com/Hendiadyoin1
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…
Reference in a new issue