Skip to content

Commit efcc95b

Browse files
committed
Fix close to 0 and close to -1 outputs.
1 parent 75e4c19 commit efcc95b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
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 PI_OVER_TWO.hi + (PI_OVER_TWO.lo + xbits.abs().get_val());
43+
return fputil::multiply_add(xbits.abs().get_val(), 0.75, PI_OVER_TWO.hi);
4444
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
4545
}
4646

@@ -118,8 +118,7 @@ LLVM_LIBC_FUNCTION(double, acos, (double x)) {
118118
if (x_abs == 1.0) {
119119
// x = 1, acos(x) = 0,
120120
// x = -1, acos(x) = pi
121-
return x == 1.0 ? 0.0
122-
: fputil::multiply_add(x_sign, PI.hi, x_sign * PI.lo);
121+
return x == 1.0 ? 0.0 : fputil::multiply_add(-x_sign, PI.hi, PI.lo);
123122
}
124123
// |x| > 1, return NaN.
125124
if (xbits.is_finite()) {

libc/test/src/math/smoke/acos_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TEST_F(LlvmLibcAcosTest, SpecialNumbers) {
2626
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(-2.0));
2727
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::acos(1.0));
2828
EXPECT_FP_EQ(0x1.921fb54442d18p1, LIBC_NAMESPACE::acos(-1.0));
29+
EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(0x1.0p-54));
2930
}
3031

3132
#ifdef LIBC_TEST_FTZ_DAZ

0 commit comments

Comments
 (0)