Round to nearest integer strange results
floating-point, haskell
Solution
It's in the specification. You can see it in section 6.4.6 of the Haskell report:
`round x` returns the nearest integer to `x`, the even integer if `x` is equidistant between two integers.
As pointed out by @dflemstr, this is in accordance with the IEEE Standard for Floating-Point Arithmetic.
Problem
Is there an official specification for the `round` function in Haskell? In GHCi version 7.0.3 I see the following behaviour: ``` ghci> round (0.5 :: Double) 0 ghci> round (1.5 :: Double) 2 ``` Since both 0.5 and 1.5 are representable exactly as floating point numbers, I expected to see the same behaviour as in Python 2: ``` >>> round(0.5) 1.0 >>> round(1.5) 2.0 ``` Is there a rationale for the difference, or is it a quirk of GHCi?