User: does 0.1 plus 0.2 equal 0.3?
Computer: nope
User: what's the difference?
Computer: 5.551115123125783e-17
User: holy **** why
User: truncate 2.51 to two decimal places please
Computer: okay, here you go: 2.50
User: what the **** is wrong with you?
aka "computer math"
julia> 0.1 + 0.2
0.30000000000000004
>>> 0.1 + 0.2
0.30000000000000004
> 0.1 + 0.2
[1] 0.3
> format(0.1 + 0.2, nsmall = 17)
[1] "0.30000000000000004"
>>> 0.1 + 0.2
ans = 0.30000
>>> format long
>>> 0.1 + 0.2
ans = 0.300000000000000
>>> output_precision
ans = 15
>>> output_precision(17)
>>> 0.1 + 0.2
ans = 0.30000000000000004
David Goldberg. "What Every Computer Scientist Should Know About Floating-Point Arithmetic,'' ACM Computing Surveys, Vol. 23, #1, March 1991, pp. 5-48.
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Package | Floating Point | Precision | Base |
---|---|---|---|
FixedPointDecimals.jl | no | configurable | 10 |
DecFP.jl (IEEE 754) | yes | configurable | 10 |
FixedPointNumbers.jl | no | configurable | 2 |
ArbFloats.jl | yes | arbitrary | 2 |
BigFloats (Base) | yes | arbitrary | 2 |