[libc-commits] [libc] [llvm] [libc][math] Added missing floating point exception for atanpif16 (PR #186597)
via libc-commits
libc-commits at lists.llvm.org
Sun Mar 15 03:51:23 PDT 2026
================
@@ -120,7 +120,19 @@ LLVM_LIBC_FUNCTION(float16, atanpif16, (float16 x)) {
// Case 1: |x| <= 0.5 - Direct polynomial evaluation
if (LIBC_LIKELY(x_abs <= 0.5)) {
double result = atanpi_eval(x_abs);
- return signed_result(result);
+ float16 s_result = signed_result(result);
+ // clear the underflow raised by casting
+ fputil::clear_except_if_required(FE_UNDERFLOW);
+ int rounding = fputil::quick_get_round();
+ // values checked through exhaustive testing which rounded up/down and
+ // caused spurious or missing underflow
+ bool except_value = (rounding == FE_UPWARD && xbits.uintval() == 0x0a48) ||
+ (rounding == FE_DOWNWARD && xbits.uintval() == 0x8a48);
+
+ if (result != 0.0 && result < 0x1p-14 && !except_value)
+ fputil::raise_except_if_required(FE_UNDERFLOW);
----------------
Sukumarsawant wrote:
I did try to remove it completely, but it does miss raising an exception for some values.
```CPP
if (FPBits(s_result).is_subnormal())
fputil::raise_except_if_required(FE_UNDERFLOW);
```
removed the except value condition since it's handled before that and returns early.
https://github.com/llvm/llvm-project/pull/186597
More information about the libc-commits
mailing list