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
2009-07-22 09:39:12
cool, is there a built in (out of curiosity)
Peter
2009-07-22 09:43:05
@Peter: no, according to Hoogle.
yairchu
2009-07-22 09:56:33