Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions libc/src/math/generic/sinf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ LLVM_LIBC_FUNCTION(float16, sinf16, (float16 x)) {
return r.value();
}

// Exhaustive tests show that for |x| <= 0x13d0, 1ULP rounding errors occur.
// To fix this, the following apply:
// - When x >= 0, and rounding upward, sin(x) == x.
// - When x < 0, and rounding downward, sin(x) == x.
// - When x < 0, and rounding upward, sin(x) == (x - 1ULP)
int rounding = fputil::quick_get_round();

// Exhaustive tests show that for |x| <= 0x1.f4p-11, 1ULP rounding errors
// occur. To fix this, the following apply:
if (LIBC_UNLIKELY(x_abs <= 0x13d0)) {
// When x >= 0, and rounding upward, sin(x) == x.
if (LIBC_UNLIKELY(x_abs == 0U))
return x;

// When x < 0, and rounding downward, sin(x) == x.
if ((rounding == FE_UPWARD && xbits.is_pos()) ||
(rounding == FE_DOWNWARD && xbits.is_neg()))
return x;

// When x < 0, and rounding upward, sin(x) == (x - 1ULP)
if (rounding == FE_UPWARD && xbits.is_neg()) {
x_u--;
return FPBits(x_u).get_val();
Expand Down
Loading