incorrect random library equality implementation?
The Boost 1.33.0 random library equality operators seem to be implemented incorrectly. For example, in file random/lagged_fibonacci.hpp starting at line 390 we have the following: friend bool operator==(const lagged_fibonacci_01& x, const lagged_fibonacci_01& y) { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); } The std::equal() call is comparing an array of doubles using operator == which I thought was impossible for floating point types due to their inexact nature et al. This is causing all the test cases using floating point types to fail on AmigaOS with GCC 3.4.4. Is this an implementation error or am I missing something? --Steven
On 29/08/05, Steven Solie
The std::equal() call is comparing an array of doubles using operator == which I thought was impossible for floating point types due to their inexact nature et al.
A (radix 2) floating-point number will never be exactly equal to one seventh, for example, because it's not representable. The other issue is that roundoff error will make things such as 1./3*3 not result in exactly 1. That doesn't mean that you can't compare between them for equality. If one float is a copy of another, then they should be bitwise equal. Also, floating-point operations are deterministic, so the same sequence of operations -- in exactly the same environment -- should also yeild bitwise equal results. Since, afaik, PRNGs should only be equal because one is a copy of another or they're at the same point in their cycle, operator== should be fine. - Scott McMurray
participants (2)
-
me22
-
Steven Solie