in reply to Re^2: Small Perl 6 discoveries III, Ints
in thread Small Perl 6 discoveries III, Ints

> 1.000000000000001e0 - 1e0 0 > 1.000000000000001e0 - 1 1.11022302462516e-15

Replies are listed 'Best First'.
Re^4: Small Perl 6 discoveries III, Ints
by syphilis (Archbishop) on Sep 29, 2017 at 05:16 UTC
    > 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
      This too is due to the exponential notation always generating Nums instead of Rats. So if you substract a value with rounding errors minus the same value without rounding errors, what you have left is the rounding error.


      holli

      You can lead your users to water, but alas, you cannot drown them.
        The rounding errors aren't the problem. It's the inconsistency of the rounding errors that's worrying us.
      > my $a = 1.000000000000001e0; my $b = 1e0; $a - $b 0 > $a - 1 1.11022302462516e-15 > $b - 1 1.11022302462516e-15 > $a.WHERE 4405787632 > $b.WHERE 4405787632 > 1.000000000000001e0 == 1e0 True
        > 1.000000000000001e0 == 1e0 True

        Oh dear, that is awful.
        Someone should inform the perl6 developers of that behaviour - assuming, of course, that they haven't yet fixed it.

        Cheers,
        Rob