in reply to Small Perl 6 discoveries III, Ints

Well, mystery sort of solved. It seems to be some kind of misguided parser optimization. It will reuse a floating-point literal for another value that's approximately equal.
> my $a = 2e25; my $b = 20e24; $a - $b 0 > (Int($a), $a.WHERE) (20000000000000001811939328 4431024856) > (Int($b), $b.WHERE) (20000000000000001811939328 4431024856) > my $c = Num('2e25'); my $d = Num('20e24'); $c - $d 4294967296 > (Int($c), $c.WHERE) (20000000000000001811939328 4431025568) > (Int($d), $d.WHERE) (19999999999999997516972032 4431025664)
Observe that $a and $b refer to the same object (they have the same address), while $c and $d are distinct.

Replies are listed 'Best First'.
Re^2: Small Perl 6 discoveries III, Ints
by syphilis (Archbishop) on Sep 29, 2017 at 02:26 UTC
    It will reuse a floating-point literal for another value that's approximately equal

    I'll speculate that it will only engage in "reuse" when the two values are exactly equal. (Bear in mind that 2e25 and 20e24 are exactly equal.)
    So it should be a valid optimization - it's only being brought undone by the miscalculation of 20e24.

    The miscalculation of 20e24 is a bug in perl6 that should be reported, though FAIK it might already have been fixed.

    UPDATE: The same miscalculation is also a bug in perl5 - but such miscalculations are already known in perl 5

    Cheers,
    Rob
      > 1.000000000000001e0 - 1e0 0 > 1.000000000000001e0 - 1 1.11022302462516e-15
        > 1.000000000000001e0 - 1e0 0
        Certainly can't reproduce that one on perl5 ;-)
        It looks buggy to me.
        It appears that 1.000000000000001e0 has been rounded to 1.00000000000000e0 prior to doing the subtraction.
        Though it's also possible that 0.000000000000001e0 has been rounded to 0 when the value is printed out.
        Does perl6 actually assert that 1.000000000000001e0 == 1e0 ??

        Of course, "double" builds of perl5 will round 1.000000000000001e0 to 1e0 prior to printing it out:
        C:\>perl -le "print 1.000000000000001e0;" 1
        but that's different to what appears to be happening in the given example. (And even though perl5 has printed out "1", it knows damn well that 1.000000000000001e0 != 1e0)

        Cheers,
        Rob