G'day all.
Richard A. O'Keefe wrote:
That's one of the warning signs I watch out for. "Never compare floats for
equality" is a sure sign of someone who thinks they know about
floats but don't.
Quoting Roman Leshchinskiy <[EMAIL PROTECTED]>:
Hmm. Personally, I've never seen an algorithm where comparing for exact
equality was algorithmically necessary.
One trick I've occasionally used is to avoid the need for a discriminated
union of floating point and integer types by just using a floating point
number.
If you ignore bitwise operations and division/remainder, any integer
operation that doesn't cause overflow on 32-bit integers will work just
the same if you use IEEE-754 64-bit floating point numbers instead.
That includes equality. Moreover, you even get a few more significant
bits of precision.
In these days of fast 64 and 128 bit words, it might not be entirely
moral, but it works.
Cheers,
Andrew Bromage
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe