Testing if a Double is an Integral value in Haskell?

haskell

Solution

This looks fine and idiomatic to me, though you probably want to use `round` rather than `floor`. You could also consider using `approxRational` and checking that the denominator of the result is `1`:

isInteger x = denominator (approxRational x 0.00001) == 1

Problem

I have a list areas :: [Double]. Now I want to filter this list for those which are actually integral values. I want to do something like this for my predicate: ``` isInteger :: Double -> Bool isInteger x = abs (fromIntegral (floor x) - x) < delta where delta = 0.00001 ``` However, I would guess there is a better way to do this. Is there a Haskell idiom for checking if a real value is an integer?

Original source