Boost logo

Boost Users :

From: Andrej van der Zee (mavdzee_at_[hidden])
Date: 2007-12-19 23:47:47


Hi,

I was wondering if boost provides any support for
testing equality of two doubles. In principle in C/C++
you cannot rely on equality because it uses bitwise
comparison of doubles and in arithmetic expressions
results may have lost some precession. An example will
help:

#include <iostream>

int main(void)
{
  double start = 3.123;
  double end = 4.124;
  double diff = end - start; // == 1.001 ???

  if (diff != 1.001)
  {
    std::cout << diff << " and " << 1.001 << " are not
equal" << std::endl;
  }
}

On my machine, this example outputs:
1.001 and 1.001 are not equal

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.

So does boost have anything for this I don't know of?
Or any other libraries?

Thanks,
Andrej

      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/


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