syphilis has asked for the wisdom of the Perl Monks concerning the following question:
I was surprised that it output:my $d_1 = 0.1e0; # double 0.1 ( == 3602879701896397/3602879701896396 +8 ) my $r_1 = 0.1; # rational 1/10 my $d_2 = 0.10000000000000001e0;# double, same value as $d_1 my $r_2 = 0.10000000000000001; # rational 10000000000000001/100000000 +000000000 # check that $d_1 == 3602879701896397/36028797018963968 say "not ok 0" if $d_1 != 3602879701896397/36028797018963968; # Check that $d_1 != 1 / 10; say "not ok 1" if $d_1 == 1 / 10; # Check that $d_1 and $d_2 are assigned to exactly the same value: say "not ok 2" if $d_1 != $d_2; # Check that $r_ and $r_2 are assigned different values: say "not ok 3" if $r_1 == $r_2; # Since $r_1 and $r_2 are unequal, $d_1 should not be equal to both $r +_1 && $r_2. # We check this, interchanging lhs and rhs operands in case that makes + a # difference: say "not ok 4" if ($d_1 == $r_1 && $d_1 == $r_2); say "not ok 5" if ($r_1 == $d_1 && $r_2 == $d_1); # Similarly $d_2 should not be equal to both $r_1 and $r_2: say "not ok 6" if ($d_2 == $r_1 && $d_2 == $r_2); say "not ok 7" if ($r_1 == $d_2 && $r_2 == $d_2); say Rat($d_1); say Rat($d_2);
However, I think I understand what's happening.not ok 1 not ok 4 not ok 5 not ok 6 not ok 7 0.1 0.1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [Raku] Arcane treatment of doubles and rationals
by holli (Abbot) on Apr 03, 2021 at 22:41 UTC | |
by syphilis (Archbishop) on Apr 04, 2021 at 00:24 UTC | |
by holli (Abbot) on Apr 04, 2021 at 12:59 UTC | |
by syphilis (Archbishop) on Apr 04, 2021 at 13:26 UTC | |
by holli (Abbot) on Apr 04, 2021 at 13:34 UTC | |
|
Re: [Raku] Arcane treatment of doubles and rationals
by syphilis (Archbishop) on Apr 04, 2021 at 13:04 UTC | |
by holli (Abbot) on Apr 04, 2021 at 13:16 UTC | |
by syphilis (Archbishop) on Apr 05, 2021 at 05:18 UTC | |
by syphilis (Archbishop) on Apr 06, 2021 at 12:03 UTC |