diff --git a/AK/Math.h b/AK/Math.h index 8424ec8f2f1..d7aaf9ed111 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -250,7 +250,7 @@ constexpr T acos(T value) CONSTEXPR_STATE(acos, value); // FIXME: I am naive - return Pi + asin(value); + return static_cast(0.5) * Pi - asin(value); } template diff --git a/Tests/LibM/test-math.cpp b/Tests/LibM/test-math.cpp index 35bbab3bbe2..6368aa293f7 100644 --- a/Tests/LibM/test-math.cpp +++ b/Tests/LibM/test-math.cpp @@ -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))); +}