[Haskell-cafe] haskell gsoc proposal for richer numerical type classes and supporting algorithms

Gregory Crosswhite gcross at phys.washington.edu
Thu Apr 8 22:06:25 EDT 2010

On Apr 8, 2010, at 6:53 PM, Daniel Fischer wrote:

> Am Freitag 09 April 2010 02:51:23 schrieb Gregory Crosswhite:
> Yes, but 1/0 isn't a NaN:
> Prelude> isNaN (1.0/0.0)
> False
> Prelude> isNaN (0.0/0.0)
> True
> Prelude> 1.0/0.0
> Infinity
> Prelude> 0.0/0.0
> NaN
> Prelude> (0.0/0.0) == (0.0/0.0)
> False

Curse you for employing the dirty trick of employing easily verifiable facts to prove me wrong!  :-)

> Yup. But using (==) on floating point numbers is dangerous even without 
> NaNs. Warning against that can be beneficial.

Fair enough.

On a tangental note, I've considered coding up a package with an "AlmostEq" typeclass that allows one to test for approximate equality.  The problem is that different situations call for different tolerances so there is no standard "approximate equal" operator that would work for everyone, but there might be a tolerance that is "good enough" for most situations where it would be needed (such as using QuickCheck to test that two different floating-point functions that are supposed to return the same answer actually do so) to make it worthwhile to have a standard package for this around for the sake of convenience.

Anyone have any thoughts on this?


More information about the Haskell-Cafe mailing list