// -*-C++-*- #include "vecmathlib.h" #include #include #include #include #include #include using namespace std; int num_errors = 0; template struct vecmathlib_test { typedef typename realvec_t::boolvec_t boolvec_t; typedef typename realvec_t::intvec_t intvec_t; typedef typename realvec_t::int_t int_t; typedef typename realvec_t::uint_t uint_t; typedef typename realvec_t::real_t real_t; // Short names for type casts typedef real_t R; typedef int_t I; typedef uint_t U; typedef realvec_t RV; typedef intvec_t IV; typedef boolvec_t BV; typedef vecmathlib::floatprops FP; // Test each function with this many random values static int const imax = 10000; // Require that 3/4 of the digits are correct static real_t constexpr accuracy = pow(realvec_t::epsilon(), R(0.75)); static realvec_t random(real_t const xmin, real_t const xmax) { realvec_t x; for (int i=0; i static void check(char const* const func, real_t fstd(typename A::scalar_t), realvec_t fvml(A), A const x, real_t const accuracy) { realvec_t rstd; for (int i=0; i realvec_t(accuracy) * (fabs(rstd) + fabs(rvml) + realvec_t(1.0)))) { ++ num_errors; cout << setprecision(realvec_t::digits10+2) << "Error in " << func << "(" << x << "):\n" << " fstd(x)=" << rstd << "\n" << " fvml(x)=" << rvml << "\n" << flush; } } template static void check(char const* const func, real_t fstd(typename A::scalar_t, typename B::scalar_t), realvec_t fvml(A, B), A const x, B const y, real_t const accuracy) { realvec_t rstd; for (int i=0; i realvec_t(accuracy) * (fabs(rstd) + fabs(rvml) + realvec_t(1.0)))) { ++ num_errors; cout << setprecision(realvec_t::digits10+1) << "Error in " << func << "(" << x << "," << y << "):\n" << " fstd(x,y)=" << rstd << "\n" << " fvml(x,y)=" << rvml << "\n" << flush; } } template static void check(char const* const func, real_t fstd(typename A::scalar_t, typename B::scalar_t, typename C::scalar_t), realvec_t fvml(A, B, C), A const x, B const y, C const z, real_t const accuracy) { realvec_t rstd; for (int i=0; i realvec_t(accuracy) * (fabs(rstd) + fabs(rvml) + realvec_t(1.0)))) { ++ num_errors; cout << setprecision(realvec_t::digits10+1) << "Error in " << func << "(" << x << "," << y<< "," << z << "):\n" << " fstd(x,y,z)=" << rstd << "\n" << " fvml(x,y,z)=" << rvml << "\n" << flush; } } template static void check(char const* const func, int_t fstd(typename A::scalar_t), intvec_t fvml(A), A const x) { intvec_t rstd; for (int i=0; i static void check(char const* const func, int fstd(typename A::scalar_t, typename B::scalar_t), intvec_t fvml(A, B), A const x, B const y) { intvec_t rstd; for (int i=0; i static void check(char const* const func, bool fstd(typename A::scalar_t), boolvec_t fvml(A), A const x) { boolvec_t rstd; for (int i=0; i>::test(); #endif #ifdef VECMATHLIB_HAVE_VEC_FLOAT_4 vecmathlib_test>::test(); #endif #ifdef VECMATHLIB_HAVE_VEC_FLOAT_8 vecmathlib_test>::test(); #endif #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_1 vecmathlib_test>::test(); #endif #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_2 vecmathlib_test>::test(); #endif #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_4 vecmathlib_test>::test(); #endif cout << "\n"; if (num_errors == 0) { cout << "SUCCESS"; } else { cout << "FAILURE"; } cout << ": " << num_errors << " errors found\n" << flush; return num_errors == 0 ? 0 : 1; }