[libc-commits] [libc] [libc][math] Improve hypotf performance. (PR #186627)

Mohamed Emad via libc-commits libc-commits at lists.llvm.org
Sun Mar 15 04:09:17 PDT 2026


https://github.com/hulxv requested changes to this pull request.

```
Failed to match func(inputs[i].x, inputs[i].y) against LIBC_NAMESPACE::testing::mpfr::get_mpfr_matcher<mpfr::Operation::Hypot>( inputs[i], func(inputs[i].x, inputs[i].y), 0.5, mpfr::RoundingMode::Nearest).
Input decimal: x: 66447676.00000000000000000000000000000000000000000000000000 y: 10747905.00000000000000000000000000000000000000000000000000
First input bits: 0x4C7D7A4F = (S: 0, E: 0x0098, M: 0x007D7A4F)
Second input bits: 0x4B240001 = (S: 0, E: 0x0096, M: 0x00240001)
Libc result: 67311296.00000000000000000000000000000000000000000000000000
MPFR result: 67311304.00000000000000000000000000000000000000000000000000
Libc floating point result bits: 0x4C8062D8 = (S: 0, E: 0x0099, M: 0x000062D8)
              MPFR rounded bits: 0x4C8062D9 = (S: 0, E: 0x0099, M: 0x000062D9)
ULP error: 1.00000000000000000000000000000000000000000000000000
```

This happens due to the condition that was changed. if we take a look on the numbers:
```
x = 66447676, y = 10747905
a^2 + b^2 = 4530811107690001  ->  fits exactly in a double, so sum_sq.lo == 0
sqrt result (double) = 67311300.0  ->  67311300 % 8 == 4, exactly on a float midpoint
```

the correction should be happened here but the condition doesn't detect it because the lower bound is still zero. should be reverted

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


More information about the libc-commits mailing list