You can see the binary representation of those `Float64`s with the `bits`
function:
julia> for i in 1:10
@show bits(a * i)
end
bits(a * i) =
"0011111111001001100110011001100110011001100110011001100110011010"
bits(a * i) =
"0011111111011001100110011001100110011001100110011001100110011010"
bits(a * i) =
"0011111111100011001100110011001100110011001100110011001100110100"
bits(a * i) =
"0011111111101001100110011001100110011001100110011001100110011010"
bits(a * i) =
"0011111111110000000000000000000000000000000000000000000000000000"
bits(a * i) =
"0011111111110011001100110011001100110011001100110011001100110100"
bits(a * i) =
"0011111111110110011001100110011001100110011001100110011001100111"
bits(a * i) =
"0011111111111001100110011001100110011001100110011001100110011010"
bits(a * i) =
"0011111111111100110011001100110011001100110011001100110011001101"
bits(a * i) =
"0100000000000000000000000000000000000000000000000000000000000000"
El lunes, 28 de diciembre de 2015, 3:59:24 (UTC-6), Yonghee Kim escribió:
>
> I wrote simple code like this
>
> ----------------------
> a = 0.2
>
> for i in 1:10
> println(a * i)
> end
> ---------------------------
>
>
> and what I got is not 0.2, 0.4, 0.6, 0.8, 1.0 ....
>
> but this.
>
> 0.2
> 0.4
> 0.6000000000000001
> 0.8
> 1.0
> 1.2000000000000002
> 1.4000000000000001
> 1.6
> 1.8
> 2.0
>
>
>
> println(0.2 * 3) does the same thing. not 0.6 but 0.6000000000000001
>
> does anyone know why this happens?
>
>