So does boost have anything for this I don't know of? Or any other libraries?
Yeah, I think the question is, " what are you really trying to do?" Even with Java's repeatable-to-the-last-bit floating point spec, this would have only mattered to me once in writing an arithmetic encoder as , in this example, debug decoders would not work with release encoders. Then, I guess the questions would be, " what other abstractions would better address my objectives?" Close is supposed to be good enough for floating point and I wouldn't even rely on a given test branching reproducibly. For example, let's say you are trying to follow a signal and have a locked and unlocked state and look at behaviour as you try to obtain lock. Presumably, the output would vary a little if you chose unlocked for an extra cycle or two but who would care? You really have to look at floating point as not-so-deterministic. If you are tracking money or something, ints or strings would be better.
Date: Wed, 19 Dec 2007 20:47:47 -0800 From: mavdzee@yahoo.co.uk To: Boost-users@lists.boost.org Subject: [Boost-users] double arithmetic precession and equality
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
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________ Share life as it happens with the new Windows Live. http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_122007