|
Boost Users : |
From: John Maddock (john_at_[hidden])
Date: 2007-12-20 04:09:52
Andrej van der Zee wrote:
> Hi,
>
> I was wondering if boost provides any support for
> testing equality of two doubles.
You could take a look at the "close_at_tolerance" class in
boost/test/floating_point_comparison.hpp, but I'm not sure it's all that
easy to use: the tolerance has to be specified in percentage points.
The current SVN trunk (and Boost-1.35 when it's released) also has this
function:
http://svn.boost.org/svn/boost/trunk/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/error_test.html
for computing the relative difference between two floating point values.
> I am using a lot of arithmetic expressions on
> floating-point values and also need to test for
> equality. Also, at compile-time I do not know the
> precession so comparing within the range of an epsilon
> seems impossible.
Well you're going to have to define an acceptable tolerance for the
definition of "equal", as no library can do that for you. What do you need
this for? Testing for equality in mathematical routines is IMO extremely
rare, if you're testing the result of calculations then you might want to
take a look at how the special functions test cases handle this in the
Boost.Math library (again current Trunk and next release only).
HTH, John.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net