From 405151b3dffa14ce5c4407be025eeadb15181c29 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 6 Jun 2013 13:47:52 -0400 Subject: Allow offset when checking for errors Offset can handle cyclic functions, such as remainder. --- test.cc | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'test.cc') diff --git a/test.cc b/test.cc index 91a444b..20b3aa8 100644 --- a/test.cc +++ b/test.cc @@ -456,17 +456,53 @@ struct vecmathlib_test { template static void check_real(const char* const func, + real_t fstd(typename A::scalar_t x, B y), + realvec_t fvml(A x, B y), + const A x, const B y, + const real_t accuracy) + { + realvec_t rstd; + for (int i=0; i realvec_t(accuracy) * scale; + if (any(isbad)) { + ++ num_errors; + cout << setprecision(realvec_t::digits10+2) + << "Error in " << func << "(" << x << "," << y << " " + << "[" << hex(x) << "],[" << hex(y) << "]):\n" + << " fstd(x,y)=" << rstd << " [" << hex(rstd) << "]\n" + << " fvml(x,y)=" << rvml << " [" << hex(rvml) << "]\n" + << " abs-error(x,y)=" << fabs(dr) << "\n" + << " rel-error(x,y)=" << fabs(dr) / scale << "\n" + << " isbad(x,y)=" << isbad << "\n" + << " accuracy=" << accuracy << "\n" + << flush; + } + } + + template + static void check_real(const char* const func, real_t fstd(typename A::scalar_t x, typename B::scalar_t y), realvec_t fvml(A x, B y), const A x, const B y, - const real_t accuracy) + const real_t accuracy, + const realvec_t offset = RV(0.0)) { realvec_t rstd; for (int i=0; ifabs(offset/RV(2.0)), + rvml + copysign(offset, rstd-rvml), + rvml); const realvec_t dr = rstd - rvml; const realvec_t scale = fabs(rstd) + fabs(rvml) + realvec_t(1.0); const boolvec_t isbad = -- cgit v1.1