Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-08-03 14:14:19


Gennadiy Rozental wrote:
> Should be in cvs by now.

Apparently this was not quite as simple as I thought it was, because we
still need to handle the 0/0 case, the following patch does the trick:

cvs diff: Diffing boost/test
Index: boost/test/floating_point_comparison.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/test/floating_point_comparison.hpp,v
retrieving revision 1.28
diff -u -r1.28 floating_point_comparison.hpp
--- boost/test/floating_point_comparison.hpp 28 Jul 2006
15:01:01 -00001.28
+++ boost/test/floating_point_comparison.hpp 3 Aug 2006 18:08:39 -0000
@@ -71,6 +71,18 @@
             f2 > static_cast<FPT>(1) && f1 < f2 *
(std::numeric_limits<FPT>::mi
n)() )
             return static_cast<FPT>(0);
     }
+ else if(f1 == 0)
+ {
+ // Avoid 0 / 0, since we're calculating relative error
+ // the result really is zero here no matter what the denominator:
+ return 0;
+ }
+ else if(f2 == 0)
+ {
+ // We have an infinite relative error, in practice any
+ // big number returned here will cause our test to fail:
+ return 1000000; // any really big number will do.
+ }

     return f1/f2;
 }

Both of the else clauses here only kick in when there is no numeric_limits
support BTW.

Does this look OK?

Thanks, John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk