[libc-commits] [libc] [libc][math] Adding LIBC_MATH_ALWAYS_ROUND_NEAREST option (PR #201154)
via libc-commits
libc-commits at lists.llvm.org
Wed Jun 3 15:50:32 PDT 2026
=?utf-8?q?Hoàng_Minh_Thiên?=,=?utf-8?q?Hoàng_Minh_Thiên?=,
=?utf-8?q?Hoàng_Minh_Thiên?=,=?utf-8?q?Hoàng_Minh_Thiên?=,
=?utf-8?q?Hoàng_Minh_Thiên?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/201154 at github.com>
================
@@ -193,21 +200,27 @@ LIBC_INLINE float exp10m1f(float x) {
case 0x40e00000U: // x = 7.0f
return 9'999'999.0f;
case 0x41000000U: { // x = 8.0f
+#ifndef LIBC_MATH_HAS_ALWAYS_ROUND_NEAREST
----------------
DylanFleming-arm wrote:
These cases don't quite match up, for example, the x == 8 case
With `LIBC_MATH_HAS_ALWAYS_ROUND_NEAREST` OFF:
`FE_UPWARDS` or `FE_TONEAREST` return `100'000'000.0f;`, otherwise `99'999'992.0f;` (which means `FE_TONEAREST` should be returning 100'000'000.0f)
But then with `LIBC_MATH_HAS_ALWAYS_ROUND_NEAREST` ON, this would compiles as:
```
case 0x41000000U: { // x = 8.0f
return 99'999'992.0f;
}
```
This should instead be:
```
case 0x41000000U: { // x = 8.0f
#ifdef LIBC_MATH_HAS_ALWAYS_ROUND_NEAREST
return 100'000'000.0f;
#else
int rounding = fputil::quick_get_round();
if (rounding == FE_UPWARD || rounding == FE_TONEAREST)
return 100'000'000.0f;
return 99'999'992.0f;
#endif
```
This is true for the x == 9, and x == 10 cases too
https://github.com/llvm/llvm-project/pull/201154
More information about the libc-commits
mailing list