julia> 1.1 - 2*0.1
0.9000000000000001
This is not Julia-specific, it’s due to the fact that standard floating-point arithmetic doesn’t exactly represent decimal values like 1.1
and 0.1
. For example, in Python 3:
>>> 1.1 - 2*0.1
0.9000000000000001
See:
Sometimes people are surprised by the results of floating-point calculations such as
julia> 5/6
0.8333333333333334 # shouldn't the last digit be 3?
julia> 2.6 - 0.7 - 1.9
2.220446049250313e-16 # shouldn't the answer be 0?
These are not bugs in Julia. They’re consequences of the IEEE-standard 64-bit binary representation of floating-point numbers that is burned into computer hardware, which Julia and many other languages use by default.
Brief explanation
You can t…
3 Likes