[libc-commits] [libc] c0064f7 - [libc][math] Fix missing underflow exception in DyadicFloat::generic_as (#186734)
via libc-commits
libc-commits at lists.llvm.org
Wed Mar 18 07:02:43 PDT 2026
Author: Anonmiraj
Date: 2026-03-18T10:02:36-04:00
New Revision: c0064f744c01bef79babbf5853288a11cd7a3c9f
URL: https://github.com/llvm/llvm-project/commit/c0064f744c01bef79babbf5853288a11cd7a3c9f
DIFF: https://github.com/llvm/llvm-project/commit/c0064f744c01bef79babbf5853288a11cd7a3c9f.diff
LOG: [libc][math] Fix missing underflow exception in DyadicFloat::generic_as (#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
Added:
Modified:
libc/src/__support/FPUtil/dyadic_float.h
Removed:
################################################################################
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index cc0710fbf7b02..8ce041247716b 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -219,6 +219,9 @@ template <size_t Bits> struct DyadicFloat {
underflow = true;
} else if (unbiased_exp == -FPBits::EXP_BIAS - FPBits::FRACTION_LEN) {
round = true;
+ // underflow is detected pre-rounding FE_UNDERFLOW may be raised
+ // even if rounding produces a non-underflow result
+ underflow = true;
MantissaType sticky_mask = (MantissaType(1) << (Bits - 1)) - 1;
sticky = (mantissa & sticky_mask) != 0;
} else {
More information about the libc-commits
mailing list