Does anyone have an explanation for this strange rounding in haskell (GHCi, version 7.2.1). Everything seems fine unless I multiply with 100.
*Main> 1.1
1.1
*Main> 1.1 *10
11.0
*Main> 1.1 *100
110.00000000000001
*Main> 1.1 *1000
1100.0
*Main> 1.1 *10000
11000.0
Edit: what is puzzeling me is that the rounding error only shows when multiplying with 100.
Edit(2): The comments I received made me realize, that this it totally unrelated to haskell, but a general issue with floating point numbers. Numerous questions were already asked (and answered) about floating-point number oddities, where the undelying issue typcally was confusing floats with real numbers.
Perl, python, javascript and C all report 1.1 * 100.0 = 110.00000000000001
. Here is what C does
double 10.0 * 1.1 = 11.000000000000000000000000
double 100.0 * 1.1 = 110.000000000000014210854715
double 110.0 = 110.000000000000000000000000
double 1000.0 * 1.1 = 1100.000000000000000000000000
The question "why does this happen only when multiplying with 100" (even though there is a precise representation for 110.0) is still unanswered, but I suppose there is no simple answer, other than fully stepping through a floating-point multiplication (Thanks to Dax Fohl for stressing that 10 is nothing special in binary)