# Changeset 1658

Ignore:
Timestamp:
Dec 17, 2008, 4:02:00 PM (14 years ago)
Message:

Adding functions to use for fix precision comparisons (refs #470)

Location:
trunk/test
Files:
2 edited

Unmodified
Removed
• ## trunk/test/Suite.cc

 r1574 double last_error_bound = n*std::numeric_limits().epsilon()* std::min(std::abs(a), std::abs(b)); return equal_fix(a, b, last_error_bound); } bool Suite::equal_fix(double a, double b, double margin) { // using the negated comparison to catch NaN problems if (!(std::abs(a-b) <= last_error_bound)){ err() << "Error: Comparing " << a << " and " << b << "\n  Difference: " << a - b << "\n  expected difference to be at most " << last_error_bound << "\n  expected difference to be at most " << margin << std::endl; return false;
• ## trunk/test/Suite.h

 r1569 /** \return true if |\a a - \a b| <= \a margin */ bool equal_fix(double a, double b, double margin=0); /** \return true if \f$|a-b| <= N * sqrt(\epsilon) * min(|a|,|b|) \f$ where \f$\epsilon \f$ is std::numeric_limits().epsilon() bool equal_sqrt(double a, double b, unsigned long int N=1); /** apply equal on ranges [first1, last1) and [first2, ...) */ template bool equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2, unsigned int N=1); /** apply equal_fix on ranges [first1, last1) and [first2, ...) */ template bool equal_range_fix(Iterator1 first1, Iterator1 last1, Iterator2 first2, double margin); /** template bool Suite::equal_range_fix(Iterator1 first1, Iterator1 last1, Iterator2 first2, double margin) { while (first1!=last1){ if (!this->equal_fix(*first1, *first2, margin) )   { return false; } ++first1; ++first2; } return true; } template bool Suite::test_stream(const T& t) const
Note: See TracChangeset for help on using the changeset viewer.