diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 21:56:01 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 21:56:01 -0400 |
commit | 2ad328972cad320d9c4c05ac04721d58702ebb9c (patch) | |
tree | 091991027d5f585c8744914a4fbc7ba0addb3369 | |
parent | b1d2de5c21180748ba9ce25dd650b85cfa807fa8 (diff) | |
download | vecmathlib-2ad328972cad320d9c4c05ac04721d58702ebb9c.zip vecmathlib-2ad328972cad320d9c4c05ac04721d58702ebb9c.tar.gz |
Add more tests for type conversions and rounding
-rw-r--r-- | floatprops.h | 2 | ||||
-rw-r--r-- | test.cc | 55 |
2 files changed, 53 insertions, 4 deletions
diff --git a/floatprops.h b/floatprops.h index 99deebf..3acd2d3 100644 --- a/floatprops.h +++ b/floatprops.h @@ -22,6 +22,8 @@ namespace vecmathlib { template<typename real_t> struct floatprops { // Some interesting properties are: + // min + // max // digits // epsilon // min_exponent @@ -402,10 +402,55 @@ struct vecmathlib_test { cout << " testing ceil convert_float convert_int floor rint round trunc...\n" << flush; - for (int i=0; i<imax; ++i) { - realvec_t const x = random(R(-1.0e+10), R(+1.0e+10)); + const real_t eps = FP::epsilon(); + const real_t int_min = R(numeric_limits<int_t>::min()); + const real_t int_max = R(numeric_limits<int_t>::max()); + const real_t uint_min = R(numeric_limits<uint_t>::min()); + const real_t uint_max = R(numeric_limits<uint_t>::max()); + const real_t values[] = { + R(+0.0), R(+0.1), R(+0.9), R(+1.0), R(+1.1), + R(-0.0), R(-0.1), R(-0.9), R(-1.0), R(-1.1), + R(+0.0)+eps, R(+0.1)+eps, R(+0.9)+eps, R(+1.0)+eps, R(+1.1)+eps, + R(-0.0)+eps, R(-0.1)+eps, R(-0.9)+eps, R(-1.0)+eps, R(-1.1)+eps, + R(+0.0)-eps, R(+0.1)-eps, R(+0.9)-eps, R(+1.0)-eps, R(+1.1)-eps, + R(-0.0)-eps, R(-0.1)-eps, R(-0.9)-eps, R(-1.0)-eps, R(-1.1)-eps, +#ifdef VML_HAVE_DENORMALS + +FP::min(), +FP::min()*(R(1.0)+eps), +FP::min()*R(2.0), + -FP::min(), -FP::min()*(R(1.0)+eps), -FP::min()*R(2.0), +#endif + +FP::max(), +FP::max()*(R(1.0)-eps), +FP::max()*(R(1.0)-R(2.0)*eps), + -FP::max(), -FP::max()*(R(1.0)-eps), -FP::max()*(R(1.0)-R(2.0)*eps), + +R(0.5)*FP::max(), +R(0.5)*FP::max()*(R(1.0)+eps), + -R(0.5)*FP::max(), -R(0.5)*FP::max()*(R(1.0)+eps), +#ifdef VML_HAVE_INF + +R(1.0/0.0), // +FP::infinity() + -R(1.0/0.0), // -FP::infinity() +#endif +#ifdef VML_HAVE_NAN + R(0.0/0.0), // FP::quite_NaN() +#endif + +int_min, +int_max, +uint_min, +uint_max, + -int_min, -int_max, -uint_min, -uint_max, + +int_min+R(0.1), +int_max+R(0.1), +uint_min+R(0.1), +uint_max+R(0.1), + -int_min+R(0.1), -int_max+R(0.1), -uint_min+R(0.1), -uint_max+R(0.1), + +int_min-R(0.1), +int_max-R(0.1), +uint_min-R(0.1), +uint_max-R(0.1), + -int_min-R(0.1), -int_max-R(0.1), -uint_min-R(0.1), -uint_max-R(0.1), + +int_min+R(1.0), +int_max+R(1.0), +uint_min+R(1.0), +uint_max+R(1.0), + -int_min+R(1.0), -int_max+R(1.0), -uint_min+R(1.0), -uint_max+R(1.0), + +int_min-R(1.0), +int_max-R(1.0), +uint_min-R(1.0), +uint_max-R(1.0), + -int_min-R(1.0), -int_max-R(1.0), -uint_min-R(1.0), -uint_max-R(1.0), + -R(443.9999425), + }; + const int nvalues = sizeof values / sizeof *values; + + for (int i=0; i<nvalues+imax; ++i) { + realvec_t const x = + i<nvalues ? RV(values[i]) : random(R(-1.0e+10), R(+1.0e+10)); intvec_t const n1 = random(int_t(-100), int_t(+100)); - intvec_t const n2 = random(int_t(-1000000000), int_t(+1000000000)); + //intvec_t const n2 = random(int_t(-1000000000), int_t(+1000000000)); + intvec_t const n2 = + random(numeric_limits<int_t>::min() / 2, // avoid overflow + numeric_limits<int_t>::max() / 2); realvec_t const fn1 = vecmathlib::convert_float(n1); realvec_t const fn2 = vecmathlib::convert_float(n2); realvec_t const fn1h = vecmathlib::convert_float(n1) * RV(0.25); @@ -414,7 +459,9 @@ struct vecmathlib_test { FP::convert_float, vecmathlib::convert_float, n1, accuracy()); check("convert_float", FP::convert_float, vecmathlib::convert_float, n2, accuracy()); - check("convert_int", FP::convert_int, vecmathlib::convert_int, x); + if (all(x >= RV(int_min) && x <= RV(int_max))) { + check("convert_int", FP::convert_int, vecmathlib::convert_int, x); + } check("ceil", ceil, vecmathlib::ceil, x, accuracy()); check("ceil", ceil, vecmathlib::ceil, fn1, accuracy()); check("ceil", ceil, vecmathlib::ceil, fn2, accuracy()); |