[libc-commits] [libc] Add sinf16 function (PR #116674)
via libc-commits
libc-commits at lists.llvm.org
Tue Dec 3 03:55:58 PST 2024
================
@@ -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;
----------------
overmighty wrote:
The comments don't seem to match the code here.
```suggestion
// sin(+/-0) = +/-0
if (LIBC_UNLIKELY(x_abs == 0U))
return x;
// When x > 0, and rounding upward, sin(x) == 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;
```
https://github.com/llvm/llvm-project/pull/116674
More information about the libc-commits
mailing list