This sounds like the smart thing to do

It's my preferred option, but there's a view that 17 digits is just too much clutter and only gives one a level of precision that one neither generally wants nor can comprehend.
And I think that's how choices of 12 or 15 might have come about.
So ... having print() output a "thereabouts" value is not universally condemned - given that one can always see the extra decimal digits by doing printf "%.16e", $double

However, whenever I've tried to get the full 17 decimal digits by using perl6's printf() the last 2 digits are always "0" :
C:\>perl6 -e "printf '%.16e\n', 1.7320508075688772e0;" 1.7320508075688800e+00
(The perl6 developers have been recently informed of this.)

What’s your take on the second-to-last example, where $a < $b, and yet Num($a) > Num($b)?


I speculate that there's a bug in the conversion of rational values to doubles:
C:\>perl6 -e "say Rat(0.7777777777777777777770) > Rat(0.77777777777777 +77777771);" False C:\>perl6 -e "say Num(Rat(0.7777777777777777777770)) > Num(Rat(0.77777 +77777777777777771));" True
It is known that the way that perl6 assigns doubles can result in weird discrepancies and, given that the 2 rationals are so close together in value, I would not be surprised if that method of assigning the doubles is the culprit.
Note that if you do:
C:\>perl6 -e "say Num(0.7777777777777777777770e0) == Num(0.77777777777 +77777777771e0);" True
then you avoid the "Rat to Num" conversion and get the correct result.
(The two values are deemed equal because, of course, they both equate to the same double.)

And I believe that last one-liner can equivalently be written as:
C:\>perl6 -e "say 0.7777777777777777777770e0 == 0.77777777777777777777 +71e0;" True

Cheers,
Rob

In reply to Re^3: Perl6 discoveries — floating-point by syphilis
in thread Perl6 discoveries — floating-point by Grimy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.