Changeset 1658 for trunk


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

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

Location:
trunk/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.cc

    r1574 r1658  
    8989    double last_error_bound = n*std::numeric_limits<double>().epsilon()*
    9090      std::min(std::abs(a), std::abs(b));
     91    return equal_fix(a, b, last_error_bound);
     92  }
     93
     94
     95  bool Suite::equal_fix(double a, double b, double margin)
     96  {
     97    // using the negated comparison to catch NaN problems
    9198    if (!(std::abs(a-b) <= last_error_bound)){
    9299      err() << "Error: Comparing " << a << " and " << b
    93100            << "\n  Difference: " << a - b
    94             << "\n  expected difference to be at most " << last_error_bound
     101            << "\n  expected difference to be at most " << margin
    95102            << std::endl;
    96103      return false;
  • trunk/test/Suite.h

    r1569 r1658  
    6161
    6262    /**
     63       \return true if |\a a - \a b| <= \a margin
     64    */
     65    bool equal_fix(double a, double b, double margin=0);
     66
     67    /**
    6368       \return true if \f$ |a-b| <= N * sqrt(\epsilon) * min(|a|,|b|) \f$
    6469       where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon()
     
    6671    bool equal_sqrt(double a, double b, unsigned long int N=1);
    6772
     73    /**
     74       apply equal on ranges [first1, last1) and [first2, ...)
     75    */
    6876    template<typename Iterator1, typename Iterator2>
    6977    bool equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2,
    7078                     unsigned int N=1);
     79
     80    /**
     81       apply equal_fix on ranges [first1, last1) and [first2, ...)
     82    */
     83    template<typename Iterator1, typename Iterator2>
     84    bool equal_range_fix(Iterator1 first1, Iterator1 last1, Iterator2 first2,
     85                         double margin);
    7186
    7287    /**
     
    143158
    144159
     160  template<typename Iterator1, typename Iterator2>
     161  bool Suite::equal_range_fix(Iterator1 first1, Iterator1 last1,
     162                              Iterator2 first2, double margin)
     163  {
     164    while (first1!=last1){
     165      if (!this->equal_fix(*first1, *first2, margin) )   {
     166        return false;
     167      }
     168      ++first1;
     169      ++first2;
     170    }
     171    return true;
     172  }
     173
     174
    145175  template<class T>
    146176  bool Suite::test_stream(const T& t) const
Note: See TracChangeset for help on using the changeset viewer.