//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // test cases #ifndef CASES_H #define CASES_H #include #include std::complex x[] = { std::complex( 1.e-6, 1.e-6), std::complex(-1.e-6, 1.e-6), std::complex(-1.e-6, -1.e-6), std::complex( 1.e-6, -1.e-6), std::complex( 1.e+6, 1.e-6), std::complex(-1.e+6, 1.e-6), std::complex(-1.e+6, -1.e-6), std::complex( 1.e+6, -1.e-6), std::complex( 1.e-6, 1.e+6), std::complex(-1.e-6, 1.e+6), std::complex(-1.e-6, -1.e+6), std::complex( 1.e-6, -1.e+6), std::complex( 1.e+6, 1.e+6), std::complex(-1.e+6, 1.e+6), std::complex(-1.e+6, -1.e+6), std::complex( 1.e+6, -1.e+6), std::complex(NAN, NAN), std::complex(-INFINITY, NAN), std::complex(-2, NAN), std::complex(-1, NAN), std::complex(-0.5, NAN), std::complex(-0., NAN), std::complex(+0., NAN), std::complex(0.5, NAN), std::complex(1, NAN), std::complex(2, NAN), std::complex(INFINITY, NAN), std::complex(NAN, -INFINITY), std::complex(-INFINITY, -INFINITY), std::complex(-2, -INFINITY), std::complex(-1, -INFINITY), std::complex(-0.5, -INFINITY), std::complex(-0., -INFINITY), std::complex(+0., -INFINITY), std::complex(0.5, -INFINITY), std::complex(1, -INFINITY), std::complex(2, -INFINITY), std::complex(INFINITY, -INFINITY), std::complex(NAN, -2), std::complex(-INFINITY, -2), std::complex(-2, -2), std::complex(-1, -2), std::complex(-0.5, -2), std::complex(-0., -2), std::complex(+0., -2), std::complex(0.5, -2), std::complex(1, -2), std::complex(2, -2), std::complex(INFINITY, -2), std::complex(NAN, -1), std::complex(-INFINITY, -1), std::complex(-2, -1), std::complex(-1, -1), std::complex(-0.5, -1), std::complex(-0., -1), std::complex(+0., -1), std::complex(0.5, -1), std::complex(1, -1), std::complex(2, -1), std::complex(INFINITY, -1), std::complex(NAN, -0.5), std::complex(-INFINITY, -0.5), std::complex(-2, -0.5), std::complex(-1, -0.5), std::complex(-0.5, -0.5), std::complex(-0., -0.5), std::complex(+0., -0.5), std::complex(0.5, -0.5), std::complex(1, -0.5), std::complex(2, -0.5), std::complex(INFINITY, -0.5), std::complex(NAN, -0.), std::complex(-INFINITY, -0.), std::complex(-2, -0.), std::complex(-1, -0.), std::complex(-0.5, -0.), std::complex(-0., -0.), std::complex(+0., -0.), std::complex(0.5, -0.), std::complex(1, -0.), std::complex(2, -0.), std::complex(INFINITY, -0.), std::complex(NAN, +0.), std::complex(-INFINITY, +0.), std::complex(-2, +0.), std::complex(-1, +0.), std::complex(-0.5, +0.), std::complex(-0., +0.), std::complex(+0., +0.), std::complex(0.5, +0.), std::complex(1, +0.), std::complex(2, +0.), std::complex(INFINITY, +0.), std::complex(NAN, 0.5), std::complex(-INFINITY, 0.5), std::complex(-2, 0.5), std::complex(-1, 0.5), std::complex(-0.5, 0.5), std::complex(-0., 0.5), std::complex(+0., 0.5), std::complex(0.5, 0.5), std::complex(1, 0.5), std::complex(2, 0.5), std::complex(INFINITY, 0.5), std::complex(NAN, 1), std::complex(-INFINITY, 1), std::complex(-2, 1), std::complex(-1, 1), std::complex(-0.5, 1), std::complex(-0., 1), std::complex(+0., 1), std::complex(0.5, 1), std::complex(1, 1), std::complex(2, 1), std::complex(INFINITY, 1), std::complex(NAN, 2), std::complex(-INFINITY, 2), std::complex(-2, 2), std::complex(-1, 2), std::complex(-0.5, 2), std::complex(-0., 2), std::complex(+0., 2), std::complex(0.5, 2), std::complex(1, 2), std::complex(2, 2), std::complex(INFINITY, 2), std::complex(NAN, INFINITY), std::complex(-INFINITY, INFINITY), std::complex(-2, INFINITY), std::complex(-1, INFINITY), std::complex(-0.5, INFINITY), std::complex(-0., INFINITY), std::complex(+0., INFINITY), std::complex(0.5, INFINITY), std::complex(1, INFINITY), std::complex(2, INFINITY), std::complex(INFINITY, INFINITY) }; enum {zero, non_zero, inf, NaN, non_zero_nan}; template int classify(const std::complex& x) { if (x == std::complex()) return zero; if (std::isinf(x.real()) || std::isinf(x.imag())) return inf; if (std::isnan(x.real()) && std::isnan(x.imag())) return NaN; if (std::isnan(x.real())) { if (x.imag() == T(0)) return NaN; return non_zero_nan; } if (std::isnan(x.imag())) { if (x.real() == T(0)) return NaN; return non_zero_nan; } return non_zero; } inline int classify(double x) { if (x == 0) return zero; if (std::isinf(x)) return inf; if (std::isnan(x)) return NaN; return non_zero; } void is_about(float x, float y) { assert(std::abs((x-y)/(x+y)) < 1.e-6); } void is_about(double x, double y) { assert(std::abs((x-y)/(x+y)) < 1.e-14); } void is_about(long double x, long double y) { assert(std::abs((x-y)/(x+y)) < 1.e-14); } #endif // CASES_H