Rijk-Jan van Haaften wrote:
Hello,
While I were writing a RealFrac implementation for BigDouble's (for high-precision computations) I found a strange implementation of round in the standard prelude (from the haskell definition):
round x = let (n,r) = properFraction x m = if r < 0 then n - 1 else n + 1 in case signum (abs r - 0.5) of -1 -> n 0 -> if even n then n else m 1 -> m
The strange case is if signum (abs r - 0.5) is 0: such numbers are round to the nearest EVEN integer. In mathematics, computer science (the studies I'm doing) and physics, as far as I know, it is usual to round such numbers up, rather than to the nearest integer. For example:
Rounding to the nearest even number is considered the best practice by people doing numerical analysis. Even when I went to school (25 - 30 years ago) we were taught to round to the nearest even number, so it's not exactly new. -- Lennart