GNU bash, version 4.2.24:
$> printf "%.0f, %.0f\n" 48.5 49.5
48, 50
Ruby 1.8.7
> printf( "%.0f, %.0f\n", 48.5, 49.5 )
48, 50
Perl 5.12.4
$> perl -e 'printf( "%.0f, %.0f\n", 48.5, 49.5 )'
48, 50
gcc 4.5.3:
> printf( "%.0f, %.0f\n", 48.5, 49.5 );
48, 50
GHC, version 7.0.4:
> printf "%.0f, %.0f\n" 48.5 49.5
49, 50
Wikipedia says that this kind of rounding is called round half to even:
This is the default rounding mode used in IEEE 754 computing functions and operators.
Why is this rounding used by default in C, Perl, Ruby and bash, but not in Haskell?
Is it some sort of tradition or standard? And if it is a standard, why it’s used by those languages and not used by Haskell? What is a point of rounding half to even?
The only difference is that
printfisn’t usinground— presumably because it has to be able to round to more than just whole integers. I don’t think IEEE 754 specifies anything about how to implementprintf-style formatting functions, just rounding, which Haskell does correctly.It would probably be best if
printfwas consistent withroundand other languages’ implementations, but I don’t think it’s really a big deal.