Skip Menu |
Report information
Id: 132329
Status: open
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)


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