Given the pre-alpha nature of Perl6, as well as its several development branches, it's a good idea to identify what build you're working with. Particularly since Perl6 is anything that passes the Perl6 test suite, which is supposed to be thorough.

If what you're describing is really happening (and if I understand your Perl6 code, which I may not), there's a problem. Could you build some tests similar to the Perl5 code below? One would expect floating point errors, but not as significant as 0.1 when adding only four numbers.

In translating, I tried to keep the same concepts in place, replacing the Perl6 [+] operator with List::Util's sum() operator. The rest was pretty much just small syntax changes.

Perl5 test code follows:

use v5.12; use strict; use warnings; use List::Util qw/sum/; BEGIN{ say "# Running tests: "; } use Test::More tests => 14; my %ball = map { $_ => 1 } 1 .. 8; $ball{3} = .9; my $a1 = sum @ball{ 1 .. 4 }; my $a2 = sum @ball{ 5 .. 8 }; my $result1 = sum( @ball{ 1 .. 4 } ) <=> sum( @ball{ 5 .. 8 } ); my $result2 = $a1 <=> sum @ball{ 5 .. 8 }; note "\nEnvironment:"; note "\t%ball holds:"; note "\t\t$_ => $ball{$_}" for sort keys %ball; note "\t\$a1 = $a1\t \$a2 = $a2"; note "\t\$result1 = $result1\t \$result2 = $result2\n\nTests:"; is_deeply( \%ball, { 1 => 1, 2 => 1, 3 => .9, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 1 }, "%ball has expected keys and values." ); cmp_ok( $ball{3}, '==', 0.9, "\$ball{3} ($ball{3}) == 0.9" ); cmp_ok( sum( @ball{ 1 .. 8 } ), '==', 7.9, "sum( \@ball{ 1 .. 8 } ) == 7.9" ); cmp_ok( $a1, '==', 3.9, "\$a1 == 3.9" ); cmp_ok( $a2, '==', 4.0, "\$a2 == 4.0" ); cmp_ok( $a1, '<', $a2, '$a1 (' . $a1 . ') < $a2 (' . $a2 . ')' ); cmp_ok( $result1, '==', $result2, '$result1 (' . $result1 . ') == $result2 (' . $result2 . ')' ); cmp_ok( $a1, '<', sum( @ball{ 5 .. 8 } ), '$a1 (' . $a1 . ') < sum @ball{ 5 .. 8 } (' . sum( @ball{ 5 .. 8 } ) . ')' ); cmp_ok( $a2, '>', sum( @ball{ 1 .. 4 } ), '$a2 (' . $a2 . ') > sum @ball{ 1 .. 4 } (' . sum( @ball { 1 .. 4 } ) . ')' ); cmp_ok( sum( @ball{ 1 .. 4 } ), '<', sum( @ball{ 5 .. 8 } ), 'sum( @ball{ 1 .. 4 } ) (' . sum( @ball{ 1 .. 4 } ) . ')' . ' < ' . 'sum( @ball{ 5 .. 8 } ) (' . sum( @ball{ 5 .. 8 } ) . ')' ); cmp_ok( 3.9 <=> 4, '==', -1, "3.9 <=> 4 == -1" ); cmp_ok( 4 <=> 3.9, '==', 1, "4 <=> 3.9 == 1" ); cmp_ok( 3.9 <=> 3.9, '==', 0, "3.9 <=> 3.9 == 0" ); cmp_ok( 4 <=> 4, '==', 0, "4 <=> 4 == 0" );

And the output:

# Running tests: 1..14 # # Environment: # %ball holds: # 1 => 1 # 2 => 1 # 3 => 0.9 # 4 => 1 # 5 => 1 # 6 => 1 # 7 => 1 # 8 => 1 # $a1 = 3.9 $a2 = 4 # $result1 = -1 $result2 = -1 # # Tests: ok 1 - %ball has expected keys and values. ok 2 - $ball{3} (0.9) == 0.9 ok 3 - sum( @ball{ 1 .. 8 } ) == 7.9 ok 4 - $a1 == 3.9 ok 5 - $a2 == 4.0 ok 6 - $a1 (3.9) < $a2 (4) ok 7 - $result1 (-1) == $result2 (-1) ok 8 - $a1 (3.9) < sum @ball{ 5 .. 8 } (4) ok 9 - $a2 (4) > sum @ball{ 1 .. 4 } (3.9) ok 10 - sum( @ball{ 1 .. 4 } ) (3.9) < sum( @ball{ 5 .. 8 } ) (4) ok 11 - 3.9 <=> 4 == -1 ok 12 - 4 <=> 3.9 == 1 ok 13 - 3.9 <=> 3.9 == 0 ok 14 - 4 <=> 4 == 0

It seemed foolish building so many redundant tests, but if what you are trying to highlight is an actual bug it would merit even more tests than this to be sure. As you can see, I couldn't reproduce it in Perl5. I intentionally stayed away from tests that might have accumulated floating point errors, which should be a different topic. Having 3.9 suddenly test greater than 4 would be more than a small floating point rounding error. I wish I had Perl6 installed to try to reproduce it there, but don't wish so much as to actually install it yet.

You've got to love Test::More. I assume some similar framework exists for Perl6 testing.

Update: Added a few more tests. Why, I don't know. ;)


Dave


In reply to Re: Is it a bug in perl6 ? by davido
in thread Is it a bug in perl6 ? by ej8000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.