[libc-commits] [libc] [llvm] [libc][math] Added missing floating point exception for atanpif16 (PR #186597)

via libc-commits libc-commits at lists.llvm.org
Sat Mar 14 07:26:17 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Zorojuro (Sukumarsawant)

<details>
<summary>Changes</summary>

This PR intends to fix the missed FP exceptions for atanpif16 

---
Full diff: https://github.com/llvm/llvm-project/pull/186597.diff


1 Files Affected:

- (modified) libc/src/math/generic/atanpif16.cpp (+12-1) 


``````````diff
diff --git a/libc/src/math/generic/atanpif16.cpp b/libc/src/math/generic/atanpif16.cpp
index c54087c7165fe..6682b886fa7a7 100644
--- a/libc/src/math/generic/atanpif16.cpp
+++ b/libc/src/math/generic/atanpif16.cpp
@@ -120,7 +120,18 @@ 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);
+
+    return s_result;
   }
 
   // case 2: 0.5 < |x| <= 1 - use double-angle reduction

``````````

</details>


https://github.com/llvm/llvm-project/pull/186597


More information about the libc-commits mailing list