Skip Menu |
Report information
Id: 132329
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: victor.adam [at] derpymail.org
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug <rakudobug [...] perl.org>
From: Victor ADAM <victor.adam [...] derpymail.org>
Subject: Rat → Num conversion isn’t monotonous
Date: Fri, 20 Oct 2017 16:33:58 +0200
Download (untitled) / with headers
text/plain 626b
How to reproduce ---------------- perl6 -e 'my ($a, $b) = (0.777777777777777777777, 0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)' Expected behavior ----------------- Prints `Less Less`, or `Less Same`, depending on how rounding is done. Actual behavior --------------- Prints `Less More`. This seems inconsistent: $a is strictly smaller than $b, yet Num($a) is strictly larger than Num($b). Version information ------------------- This is Rakudo version 2017.09 built on MoarVM version 2017.09.1 implementing Perl 6.c. This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313
RT-Send-CC: perl6-compiler [...] perl.org
On Fri, 20 Oct 2017 07:34:04 -0700, victor.adam@derpymail.org wrote: Show quoted text
> How to reproduce > ---------------- > > perl6 -e 'my ($a, $b) = (0.777777777777777777777, > 0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)' > > Expected behavior > ----------------- > > Prints `Less Less`, or `Less Same`, depending on how rounding is done. > > Actual behavior > --------------- > > Prints `Less More`. This seems inconsistent: $a is strictly smaller > than $b, yet Num($a) is strictly larger than Num($b). > > Version information > ------------------- > > This is Rakudo version 2017.09 built on MoarVM version 2017.09.1 > implementing Perl 6.c. > > This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313
This appears to be not a bug but simply the goodness of floating point math. I get the same result in C: #include <stdio.h> int main(void) { puts( 777777777777777777777.0L/1000000000000000000000.0L Show quoted text
> 7777777777777777777771.0L/10000000000000000000000.0L
? "More" : "Less or Same"); return 0; } // OUTPUT: More
Download (untitled) / with headers
text/plain 116b
Should the last word in the Subject be 'monotonic' rather than 'monotonous'? -- James E Keenan (jkeenan@cpan.org)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Fri, 20 Oct 2017 07:34:04 -0700, victor.adam@derpymail.org wrote: Show quoted text
> How to reproduce > ---------------- > > perl6 -e 'my ($a, $b) = (0.777777777777777777777, > 0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)' > > Expected behavior > ----------------- > > Prints `Less Less`, or `Less Same`, depending on how rounding is done. > > Actual behavior > --------------- > > Prints `Less More`. This seems inconsistent: $a is strictly smaller > than $b, yet Num($a) is strictly larger than Num($b). > > Version information > ------------------- > > This is Rakudo version 2017.09 built on MoarVM version 2017.09.1 > implementing Perl 6.c. > > This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313
Thank you for the report. This is now fixed (specifically, the Num version now gives "Same" as there's not enough precision available to represent those Rats as different numbers) Fix: https://github.com/rakudo/rakudo/commit/a760ac3cfc6426d9bd2fb00db https://github.com/MoarVM/MoarVM/commit/b735866ddee9bd719440e5c82 Test: https://github.com/perl6/roast/commit/db0c58b5f763b085e On Fri, 20 Oct 2017 17:44:40 -0700, cpan@zoffix.com wrote: Show quoted text
> This appears to be not a bug but simply the goodness of floating point > math. I get the same result in C:
You're wrong, 2017-Zoffix. The result you got in C is because you incorrectly used doubles to do the division.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org