Skip to content

Commit

Permalink
Fix incorrect Num sequence test / Unfudge JVM
Browse files Browse the repository at this point in the history
The way JVM stringifies is accurate and the reason more stringifies
the way the author of the test tested it is due to loss of precision bug.

While MoarVM's current stringification is used by `python2` and `perl`,
I don't believe it's correct for our purposes:
    1) RT#127184 [^1] shows problem with current stringification not
        roundtripping .EVAL.perl
    2) RT#132330 [^2] shows bugs with equalities and Set/Bag/Mix types
        due to stringification used in Num.WHICH
    3) RT#127182 [^3] is a Perl 5 ticket enumerating a couple of
        issue due to their way of stringification (almost same as ours)
    4) `python3` actually switched to stringifying the Nums the JVM's
        way.
    5) The same stringification format is performed by ruby as well.
    6) Not losing precision in stringification of Num will let us
        more easily show the `.1 + .2 == .3` trick and explain what
        problem the Rats solve. Currently, `say .1e0 + .2e0` prints
        `0.3`, which makes the equation look confusingly wrong. When
        MoarVM is fixed to correctly stringfy Nums, the output will
        show where the "problem"'s coming from.

[1] https://rt.perl.org/Ticket/Display.html?id=127184
[2] https://rt.perl.org/Ticket/Display.html?id=132330
[3] https://rt.perl.org/Ticket/Display.html?id=127182
  • Loading branch information
zoffixznet committed Mar 25, 2018
1 parent f6e070b commit f0d6e49
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions integration/advent2013-day15.t
Expand Up @@ -31,11 +31,10 @@ is (1/10 + 1/10 + 1/10 == 0.3).gist, 'True', '(\o/)';

my $pi = 3.14e0;
my $earth-mass = 5.97e24; # kg
is $earth-mass.WHAT.gist, '(Num)';
is $earth-mass.WHAT.gist, '(Num)';

is_approx (0, 1e-1 ... 2)[11], 1.1, 'missed the 1';
#?rakudo.jvm todo "jvm rounding quirks"
is (0, 1e-1 ... * >= 1).gist, '(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1)', '(oops)';
is (0, 1e-1 ... * >= 1).gist, '(0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999 1.0999999999999999)', '(oops)';
is (1e0/10 + 1/10 + 1/10 == 0.3).gist, 'False', '(awww!)';

{
Expand Down

0 comments on commit f0d6e49

Please sign in to comment.