News for hackers. Stuff that matters.
Re:0.30000000000000004 by avian on Friday November 13, 2015 @05:51AM (#10559111)
I'm not sure what was the intended message of the table of examples. It is possible in many languages to get both types of ASCII representations for floating point: a nice human-readable 0.3 and the technically correct 0.30000000000000004. But some examples seem artificially biased towards one or the other. Only for Python both variants are shown. And then some examples use decimal representations, which are not floating point at all.

For instance, in Perl "print 0.1+0.2" will give you "0.3" just like in Python, while the printf format shown here will give you the non-rounded representation. And there are of-course decimal and rational number packages for Perl as well.

Re:0.30000000000000004 by Tepix on Friday November 13, 2015 @05:56AM (#10559126)
Yep, it's better to print the result of 0.1+0.2-0.3
Re:0.30000000000000004 by bmn_ on Friday November 13, 2015 @06:21AM (#10559211)
Not generally!

    $ perl -E 'say sprintf "%.64f", 0.1 + 0.2'
    0.3000000000000000000108420217248550443400745280086994171142578125
    $ perl -E 'say sprintf "%.64f", 0.1 + 0.2 - 0.3'
    0.0000000000000000000000000000000000000000000000000000000000000000
My Perl is configured with -Dusemorebits. https://metacpan.org/pod/distribution/perl/INSTALL#more-bits