Re: Small Perl 6 discoveries I, __DATA__
by jahero (Beadle) on Sep 29, 2017 at 07:47 UTC

===SORRY!=== Error while compiling c:\temp/test.p6
Pod variable $=data not yet implemented. Sorry.
at c:\temp/test.p6:8
> say $=data<HERE><Virtues>;
 [reply] [d/l] 

It says right across the top of the page you linked:
Note: these documents may be out of date. For Perl 6 documentation see docs.perl6.org; for specs, see the official test suite.
I'm going to have to point out that docs.perl6.org is not always correct either, and let the significance of the last phrase sink in. The test suite is constantly tweaked to match the behavior of the latest perl6 code, so effectively the only specification for Perl6 is perl6 (caps intentional).
 [reply] 
Re: Small Perl 6 discoveries II, Rats
by Anonymous Monk on Sep 27, 2017 at 15:09 UTC

> say 1.111111111111111111111
1.11111111111111111604544
 [reply] [d/l] 

 [reply] 

So the question becomes, why does perl6 print all those wrong digits?
> perl5 E 'say 1.111111111111111111111'
1.11111111111111
> perl6 e 'say 1.111111111111111111111'
1.11111111111111111604544
 [reply] [d/l] 







If you want arbitrary precision rational arithmetic, you can use a FatRat:
> say 1.111111111111111111111.FatRat
1.111111111111111111111
 [reply] [d/l] 

If you want arbitrary precision rational arithmetic, you can use a FatRat
I didn't know about FatRats (yes, I know very little about perl6)  so I had a bit of a play (on rakudostar2017.07) and encountered confusing results:
> my $x = 1.111111111111111111111.FatRat; my $y = 1.111111111111111111
+111.Rat; $x  $y
0
> $x == $y
True
> say $x
1.111111111111111111111
> say $y
1.11111111111111111604544
>
On the bases that $x$y==0 and $x==$y one is led to believe that $x and $y are exactly equivalent.
Yet, say() presents us with different values.
Are the 2 rationals equivalent ?
If so, then why does say() output different values ?
If not, then why do both $x$y==0 and $x==$y evaluate as "True" ?
Interestingly, 1.11111111111111111604544 is the value of the double 1.1111111111111111 (16 decimal places) rounded to 23 decimals:
C:\>perl le "printf '%.22e\n', 1.1111111111111111;"
1.1111111111111111604544e+000\n
Perhaps this ties in with:
> my $x = 1.111111111111111111111.FatRat; my $y = 1.1111111111111111.N
+um; $x  $y
0
> $x == $y
True
How does one coerce perl6 into displaying the actual numerator and denominator of these rationals ?
Cheers, Rob  [reply] [d/l] [select] 


If the Rat class isn't any more accurate than a Num, but it's much slower, then what purpose does it serve?
 [reply] 

