[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 14:12:11 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);
----------------
lntue wrote:

this might not be needed after removing clear_except_if_required.

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


More information about the libc-commits mailing list