[libcxx-commits] [libcxx] [libc++][math] Fix undue overflowing of `std::hypot(x, y, z)` (PR #93350)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 18 13:29:02 PDT 2024


PaulXiCao wrote:

> @PaulXiCao This seems to be failing with many error messages that seem legitimate:
> 
> ```
> __math/hypot.h:74:15: error: magnitude of floating-point constant too large for type 'long double'; maximum is 1.7976931348623157E+308 [-Werror,-Wliteral-range]
>       return {0x1.0p+8'190l, 0x1.0p-9'000l};
>               ^
> ```

@ldionne I am looking at this at the moment as well but do not understand yet why this happens. I have even included `static_assert`s.
```cpp
// file: hypot.h: ll.67..76
...
else { // long double
    static_assert(std::is_same_v<_Real, long double>);
    if constexpr (sizeof(_Real) == sizeof(double))
      return static_cast<std::pair<_Real, _Real>>(__math::__hypot_factors<double>());
    else {
      static_assert(-16'381 == std::numeric_limits<_Real>::min_exponent);
      static_assert(+16'384 == std::numeric_limits<_Real>::max_exponent);
      return {0x1.0p+8'190l, 0x1.0p-9'000l}; // <-- THIS LINE THROWS THE ERROR
    }
  }
```

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


More information about the libcxx-commits mailing list