summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorPeter Bindels <dascandy@gmail.com>2021-07-16 16:39:02 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-17 17:37:20 +0200
commit660a8982e79fc4a0223ee7e94034f47789383803 (patch)
tree1439411a59a39667e30c3e503539e35c623948a2 /Userland
parentc0987453e62632d3102aea524b4b825959442aa0 (diff)
downloadserenity-660a8982e79fc4a0223ee7e94034f47789383803.zip
LibM: Turn off builtins, fix tests & implementation
While trying to port to Clang we found that the functions as implemented didn't actually work, and replacing them with a blatantly broken function also did not break the tests on the GCC build. It turns out we've been testing GCC's builtins by many tests. This removes the use of builtins for LibM's tests (so we test the whole function). It turns off the denormal test for scalbn (which was not implemented) and comments out the tgamma(0.5) test which is too inaccurate to be usable (and too complicated for me to fix). The gamma function was made accurate for all other test cases, and asin received two more layers of Taylor expansion to bring it within error margin for the tests.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibM/math.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp
index 121aa10d06..adba07ede2 100644
--- a/Userland/Libraries/LibM/math.cpp
+++ b/Userland/Libraries/LibM/math.cpp
@@ -317,9 +317,9 @@ static FloatT internal_gamma(FloatT x) NOEXCEPT
// These constants were obtained through use of WolframAlpha
constexpr long long max_integer_whose_factorial_fits = (Extractor::mantissa_bits == FloatExtractor<long double>::mantissa_bits ? 20 : (Extractor::mantissa_bits == FloatExtractor<double>::mantissa_bits ? 18 : (Extractor::mantissa_bits == FloatExtractor<float>::mantissa_bits ? 10 : 0)));
static_assert(max_integer_whose_factorial_fits != 0, "internal_gamma needs to be aware of the integer factorial that fits in this floating point type.");
- if (rintl(x) == (long double)x && x <= max_integer_whose_factorial_fits) {
+ if ((int)x == x && x <= max_integer_whose_factorial_fits + 1) {
long long result = 1;
- for (long long cursor = 1; cursor <= min(max_integer_whose_factorial_fits, (long long)x); cursor++)
+ for (long long cursor = 2; cursor < (long long)x; cursor++)
result *= cursor;
return (FloatT)result;
}
@@ -811,6 +811,10 @@ long double asinl(long double x) NOEXCEPT
value += i * product_odd<9>() / product_even<10>() / 11;
i *= squared;
value += i * product_odd<11>() / product_even<12>() / 13;
+ i *= squared;
+ value += i * product_odd<13>() / product_even<14>() / 15;
+ i *= squared;
+ value += i * product_odd<15>() / product_even<16>() / 17;
return value;
}