3 ms·
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 po
by avian 11y ago
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.
- Tepix 11y agoYep, it's better to print the result of 0.1+0.2-0.3
- bmn_ 11y agoNot 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 https://metacpan.org/pod/distribution/perl/INSTALL#more-bits