[Haskell-cafe] Re: A question about "monad laws"

ajb at spamcop.net ajb at spamcop.net
Thu Feb 14 05:20:11 EST 2008

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 <rl at cse.unsw.edu.au>:

> 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

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.

Andrew Bromage

More information about the Haskell-Cafe mailing list