Am 28.10.2010 21:59, schrieb Mateusz Grotek:
> 6 * 0.2 CTRL-P 1.2
> 1.2 - 1 CTRL-P 0.2
> 6 * 0.2 - 1 CTRL-P 0.2000000000000002
>
> Squeak 4.1 #9957
>
> bug or not?
>
>
>
Not a bug. Welcome to the wonders of binary floating point arithmetic.
Binary float representation of decimals are inexact. The bit pattern you
get for 0.2 is different from the one that you get for 6 * 0.2 - 1.
You can look at the bit patterns by using the message #hex
(6 * 0.2) hex
(1.2 - 1) hex
(6 * 0.2 - 1) hex
This has nothing to do with Squeak, see the following C code for a
similar effect:
#include <stdio.h>
main() {
printf("%1.16f\n", 6 * 0.2);
printf("%1.16f\n", 1.2 - 1);
printf("%1.16f\n", 6 * 0.2 - 1);
}
The fact that Squeak prints 6 * 0.2 as 1.2 and not as 1.2000000000000002
is a result of the particular algorithm that is being used for printing
floats as decimal numbers.
Cheers,
Hans-Martin