Skip to content

Commit 3f2447c

Browse files
committed
Fix error bounds for fast pass.
1 parent 1df1984 commit 3f2447c

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

libc/src/math/generic/acos.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LLVM_LIBC_FUNCTION(double, acos, (double x)) {
4040
#else
4141
// Force the evaluation and prevent constant propagation so that it
4242
// is rounded correctly for FE_UPWARD rounding mode.
43-
return fputil::multiply_add(xbits.abs().get_val(), 0.75, PI_OVER_TWO.hi);
43+
return (xbits.abs().get_val() + 0x1.0p-160) + PI_OVER_TWO.hi;
4444
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
4545
}
4646

@@ -52,10 +52,9 @@ LLVM_LIBC_FUNCTION(double, acos, (double x)) {
5252
#else
5353
unsigned idx;
5454
DoubleDouble x_sq = fputil::exact_mult(x, x);
55-
double err = x * 0x1.0p-51;
55+
double err = xbits.abs().get_val() * 0x1.0p-51;
5656
// Polynomial approximation:
5757
// p ~ asin(x)/x
58-
5958
DoubleDouble p = asin_eval(x_sq, idx, err);
6059
// asin(x) ~ x * p
6160
DoubleDouble r0 = fputil::exact_mult(x, p.hi);

libc/src/math/generic/asin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ LLVM_LIBC_FUNCTION(double, asin, (double x)) {
7474
#else
7575
unsigned idx;
7676
DoubleDouble x_sq = fputil::exact_mult(x, x);
77-
double err = x * 0x1.0p-51;
77+
double err = xbits.abs().get_val() * 0x1.0p-51;
7878
// Polynomial approximation:
7979
// p ~ asin(x)/x
8080

libc/src/math/generic/asin_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ LIBC_INLINE DoubleDouble asin_eval(const DoubleDouble &u, unsigned &idx,
174174
double y_hi = multiply_add(k, -0x1.0p-5, u.hi); // Exact
175175
DoubleDouble y = fputil::exact_add(y_hi, u.lo);
176176
double y2 = y.hi * y.hi;
177-
err *= y2 + 0x1.0p-30;
177+
// Add double-double errors in addition to the relative errors from y2.
178+
err = fputil::multiply_add(err, y2, 0x1.0p-102);
178179
DoubleDouble c0 = fputil::quick_mult(
179180
y, DoubleDouble{ASIN_COEFFS[idx][3], ASIN_COEFFS[idx][2]});
180181
double c1 = multiply_add(y.hi, ASIN_COEFFS[idx][5], ASIN_COEFFS[idx][4]);

0 commit comments

Comments
 (0)