[libc-commits] [libc] [libc][math] Fix missing underflow exception in DyadicFloat::generic_as (PR #186734)
via libc-commits
libc-commits at lists.llvm.org
Sun Mar 15 21:24:59 PDT 2026
https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/186734
The `generic_as` function in `dyadic_float.h` had a missing `underflow = true` at the exact boundary where `unbiased_exp == -EXP_BIAS - FRACTION_LEN`.
At this boundary, the mantissa MSB maps exactly to the round bit, so out_mantissa is 0 and the result can only be 0 or min_subnormal. The value is at most min_subnormal / 2, so it is always tiny and always inexact `underflow` must be signaled. The < case and the general subnormal range both already set underflow = true this boundary case was the only gap.
this specifically fix this error in the erfcf16 function
```
Extracted erfcf16.cpp.o from archive for linking
Running exhaustive check in --rndn mode...
Missing underflow exception for x=0x1.eacp+1 (y=0x1p-24)
```
this fix may also apply to other bfloat16 missing exceptions (@Sukumarsawant)
part of: #186483
CC: @lntue
>From 66ad279730cc86d838d6eaff956477b71505b693 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Mon, 16 Mar 2026 05:59:30 +0200
Subject: [PATCH] [libc][math] Fix missing underflow exception in
DyadicFloat::generic_as
---
libc/src/__support/FPUtil/dyadic_float.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index cc0710fbf7b02..018429b30272a 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -219,6 +219,7 @@ template <size_t Bits> struct DyadicFloat {
underflow = true;
} else if (unbiased_exp == -FPBits::EXP_BIAS - FPBits::FRACTION_LEN) {
round = true;
+ underflow = true;
MantissaType sticky_mask = (MantissaType(1) << (Bits - 1)) - 1;
sticky = (mantissa & sticky_mask) != 0;
} else {
More information about the libc-commits
mailing list