Skip to content

Commit c30826c

Browse files
committed
Fix small inputs for non-FMA targets.
1 parent 2bc9c34 commit c30826c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

libc/src/math/generic/sin.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,14 @@ LLVM_LIBC_FUNCTION(double, sin, (double x)) {
420420
#ifdef LIBC_TARGET_CPU_HAS_FMA
421421
return fputil::multiply_add(x, -0x1.0p-54, x);
422422
#else
423-
int rounding_mode = fputil::quick_get_round();
424-
if (rounding_mode == FE_TOWARDZERO ||
425-
(xbits.sign() == Sign::POS && rounding_mode == FE_DOWNWARD) ||
426-
(xbits.sign() == Sign::NEG && rounding_mode == FE_UPWARD))
427-
return FPBits(xbits.uintval() - 1).get_val();
423+
if (LIBC_UNLIKELY(x_e < 4)) {
424+
int rounding_mode = fputil::quick_get_round();
425+
if (rounding_mode == FE_TOWARDZERO ||
426+
(xbits.sign() == Sign::POS && rounding_mode == FE_DOWNWARD) ||
427+
(xbits.sign() == Sign::NEG && rounding_mode == FE_UPWARD))
428+
return FPBits(xbits.uintval() - 1).get_val();
429+
}
430+
return fputil::multiply_add(x, -0x1.0p-54, x);
428431
#endif // LIBC_TARGET_CPU_HAS_FMA
429432
}
430433

0 commit comments

Comments
 (0)