Anonymous Monk brought up a really interesting discovery here
. Unfortunately, that thread got derailed, so I’m making a separate one, as suggested by Your Mother.
One of the first things I found while testing is this really interesting tidbit:
$ perl6 -e 'say 0.99999999999999999000001'
$ perl6 -e 'say 0.99999999999999999000001 > 1'
But then I realized I was using an outdated Rakudo (2017.04). So I updated to 2017.09, and now those print 1
There’s still some interesting behavior in 2017.09, though:
$ perl6 -e 'say 0.7777777777777777777770'
$ perl6 -e 'say 0.7777777777777777777771'
Note that the second number printed is strictly smaller than the first one, even though the second source number is strictly larger than the first one, spelled in the same fashion and to the same number of significant digits! However, comparison and subtraction still return exact results:
$ perl6 -e 'say 0.7777777777777777777771 > 0.7777777777777777777770'
$ perl6 -e 'say 0.7777777777777777777771 - 0.7777777777777777777770'
Okay, that’s probably because one is a Num and the other is a Rat, so let’s convert everything to Num explicitly:
$ perl6 -e 'say Num(0.7777777777777777777770)'
$ perl6 -e 'say Num(0.7777777777777777777771)'
$ perl6 -e 'say Num(0.7777777777777777777770) > Num(0.7777777777777777
$ perl6 -e 'say Num(0.7777777777777777777770) - Num(0.7777777777777777
Huh. Now they print the same, but they’re still different numbers when compared. Note that the sign of the difference got switched:
$ perl6 -e 'my $a = 0.7777777777777777777770; my $b = 0.77777777777777
+77777771; say $a <=> $b; say Num($a) <=> Num($b)'
Also interesting is that many Nums don’t survive a round-trip to Str:
$ perl6 -e 'my $a = Num(1/9); say $a == Num(Str($a))'
Can anyone point me to the Perl6 specs/docs/whatever that explain those behaviors?