Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libcxx][test][z/OS] Fix hermite.pass.cpp for HEX float #101019

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eliminating #if directives and code formatting
  • Loading branch information
zibi2 committed Jul 31, 2024
commit b4ece9122d33080c511dd44aca053d41d2c3ad9c
49 changes: 26 additions & 23 deletions libcxx/test/std/numerics/c.math/hermite.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

#include "type_algorithms.h"

inline constexpr unsigned g_max_n =
#if !(defined(__MVS__) && !defined(__BFP__))
128;
#else
39;
#endif
template <class Real>
constexpr unsigned get_maximal_order() {
if constexpr (std::numeric_limits<Real>::max_exponent10 < std::numeric_limits<Real>::max_exponent)
return 128;
else
return 39;
}

template <class T>
std::array<T, 11> sample_points() {
Expand Down Expand Up @@ -208,20 +209,23 @@ std::vector<T> get_roots(unsigned n) {

template <class Real>
void test() {
#if !(defined(__MVS__) && !defined(__BFP__))
{ // checks if NaNs are reported correctly (i.e. output == input for input == NaN)
if constexpr (
std::numeric_limits<Real>::has_quiet_NaN &&
std::numeric_limits<
Real>::has_signaling_NaN) { // checks if NaNs are reported correctly (i.e. output == input for input == NaN)
using nl = std::numeric_limits<Real>;
for (Real NaN : {nl::quiet_NaN(), nl::signaling_NaN()})
for (unsigned n = 0; n < g_max_n; ++n)
for (unsigned n = 0; n < get_maximal_order<Real>(); ++n)
assert(std::isnan(std::hermite(n, NaN)));
}

{ // simple sample points for n=0..127 should not produce NaNs.
if constexpr (std::numeric_limits<Real>::has_quiet_NaN &&
std::numeric_limits<
Real>::has_signaling_NaN) { // simple sample points for n=0..127 should not produce NaNs.
for (Real x : sample_points<Real>())
for (unsigned n = 0; n < g_max_n; ++n)
for (unsigned n = 0; n < get_maximal_order<Real>(); ++n)
assert(!std::isnan(std::hermite(n, x)));
}
#endif

{ // checks std::hermite(n, x) for n=0..5 against analytic polynoms
const auto h0 = [](Real) -> Real { return 1; };
Expand All @@ -244,21 +248,21 @@ void test() {

{ // checks std::hermitef for bitwise equality with std::hermite(unsigned, float)
if constexpr (std::is_same_v<Real, float>)
for (unsigned n = 0; n < g_max_n; ++n)
for (unsigned n = 0; n < get_maximal_order<Real>(); ++n)
for (float x : sample_points<float>())
assert(std::hermite(n, x) == std::hermitef(n, x));
}

{ // checks std::hermitel for bitwise equality with std::hermite(unsigned, long double)
if constexpr (std::is_same_v<Real, long double>)
for (unsigned n = 0; n < g_max_n; ++n)
for (unsigned n = 0; n < get_maximal_order<Real>(); ++n)
for (long double x : sample_points<long double>())
assert(std::hermite(n, x) == std::hermitel(n, x));
}

{ // Checks if the characteristic recurrence relation holds: H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x)
for (Real x : sample_points<Real>()) {
for (unsigned n = 1; n < g_max_n - 1; ++n) {
for (unsigned n = 1; n < get_maximal_order<Real>() - 1; ++n) {
Real H_next = std::hermite(n + 1, x);
Real H_next_recurrence = 2 * (x * std::hermite(n, x) - n * std::hermite(n - 1, x));

Expand Down Expand Up @@ -296,23 +300,23 @@ void test() {
}
}

#if !(defined(__MVS__) && !defined(__BFP__))
{ // check input infinity is handled correctly
if constexpr (std::numeric_limits<Real>::has_infinity) { // check input infinity is handled correctly
Real inf = std::numeric_limits<Real>::infinity();
for (unsigned n = 1; n < g_max_n; ++n) {
for (unsigned n = 1; n < get_maximal_order<Real>(); ++n) {
assert(std::hermite(n, +inf) == inf);
assert(std::hermite(n, -inf) == ((n & 1) ? -inf : inf));
}
}

{ // check: if overflow occurs that it is mapped to the correct infinity
if constexpr (std::numeric_limits<
Real>::has_infinity) { // check: if overflow occurs that it is mapped to the correct infinity
if constexpr (std::is_same_v<Real, double>) {
// Q: Why only double?
// A: The numeric values (e.g. overflow threshold `n`) below are different for other types.
static_assert(sizeof(double) == 8);
for (unsigned n = 0; n < g_max_n; ++n) {
for (unsigned n = 0; n < get_maximal_order<Real>(); ++n) {
// Q: Why n=111 and x=300?
// A: Both are chosen s.t. the first overlow occurs for some `n<g_max_n`.
// A: Both are chosen s.t. the first overlow occurs for some `n<get_maximal_order<Real>()`.
if (n < 111) {
assert(std::isfinite(std::hermite(n, +300.0)));
assert(std::isfinite(std::hermite(n, -300.0)));
Expand All @@ -324,7 +328,6 @@ void test() {
}
}
}
#endif
}

struct TestFloat {
Expand All @@ -338,7 +341,7 @@ struct TestInt {
template <class Integer>
void operator()() {
// checks that std::hermite(unsigned, Integer) actually wraps std::hermite(unsigned, double)
for (unsigned n = 0; n < g_max_n; ++n)
for (unsigned n = 0; n < get_maximal_order<double>(); ++n)
for (Integer x : {-42, -7, -5, -1, 0, 1, 5, 7, 42})
assert(std::hermite(n, x) == std::hermite(n, static_cast<double>(x)));
}
Expand Down
Loading