Note that Julia tries to print numbers at full precision by default, except
places like Array formatting where horizontal screen space is at premium.
Erik's code does print more digits, but it does not provide any more
accuracy for representing the number (this is contrary to most other
programming languages, perhaps excepting Chrome's implementation of
JavaScript)
On Thu, Mar 12, 2015 at 5:47 PM Erik Schnetter <[email protected]> wrote:
> Keeping this a bit less abstract: You can output the numbers 0.2 and 0.8
> with a bit more precision using @sprintf. For Float64, I prefer to output
> values with 17 digits, since this corresponds approximately to the values'
> internal precision.
>
> julia> @sprintf("%.17f", 0.2)
> "0.20000000000000001"
>
> julia> @sprintf("%.17f", 0.8)
> "0.80000000000000004"
>
> julia> @sprintf("%.17f", 1-0.8)
> "0.19999999999999996"
>
> (I'd really like to use "%.17g" instead, but Julia doesn't support "%g"
> yet.)
>
> -erik
>
> On Mar 12, 2015, at 16:44 , Patrick O'Leary <[email protected]>
> wrote:
> >
> > Julia does not try to hide the complexities of floating-point
> representations, so this is expected. There's a brief section in the manual
> [1] which lists some references on this topic--I personally recommend
> reading "What Every Computer Scientist Should Know About Floating-Point
> Arithmetic", but the other references are good, too.
> >
> > [1] http://julia.readthedocs.org/en/latest/manual/integers-and-
> floating-point-numbers/#background-and-references
> >
> > On Thursday, March 12, 2015 at 3:40:45 PM UTC-5, Hanrong Chen wrote:
> > julia> 1-0.8
> > 0.19999999999999996
> >
> > Is this a bug?
>
> --
> Erik Schnetter <[email protected]>
> http://www.perimeterinstitute.ca/personal/eschnetter/
>
> My email is as private as my paper mail. I therefore support encrypting
> and signing email messages. Get my PGP key from https://sks-keyservers.net
> .
>
>