[libcxx-commits] [libcxx] [libcxx][test][z/OS] Fix hermite.pass.cpp for HEX float (PR #101019)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 2 13:14:15 PDT 2024


================
@@ -26,7 +26,13 @@
 
 #include "type_algorithms.h"
 
-inline constexpr unsigned g_max_n = 128;
+template <class Real>
+constexpr unsigned get_maximal_order() {
+  if constexpr (std::numeric_limits<Real>::max_exponent10 < std::numeric_limits<Real>::max_exponent)
----------------
PaulXiCao wrote:

I had something along the lines of "Compute maximal order s.t. polynomials do not exceed maximal representable number (i.e. 10^(max_exponent10) )" in mind. But it gets quite messy as we would need to distinguish between floats that have NaNs/Infs and not.

Alternative that should suffice here: Use something similar to your original implementation without the preprocessor checks.

```cpp
template <class Real>
constexpr unsigned get_maximal_order() {
  if constexpr (std::numeric_limits<Real>::is_iec559)
    return 128;
  else { // Workaround for IBM hexadecimal floating-points.
    // Note $|H_n(x)| < 10^75$ for $n < 39$ and x in sample_points().
    static_assert(std::numeric_limits<Real>::max_exponent10 == 75);
    return 39;
  }
}
```

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


More information about the libcxx-commits mailing list