tags:

views:

223

answers:

1

If I have a floating point number in Haskell how do I test if it is a whole number.

+6  A: 
isInt x = x == fromInteger (round x)

> isInt 2
True
> isInt 2.5
False

And just a reminder: always remember the almighty curse of the floating point numbers:

> isInt (0.1^2*200)
False
> 0.1^2*200
2.0000000000000004
yairchu
cool, is there a built in (out of curiosity)
Peter
@Peter: no, according to Hoogle.
yairchu