Skip Menu |
Report information
Id: 130774
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: perl6 [at] mscha.org
Cc:
AdminCc:

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



Date: Mon, 13 Feb 2017 14:57:35 +0100
To: rakudobug [...] perl.org
Subject: [BUG] Rat.norm() doesn't normalize, but Rat.nude() does - in place!
From: Michael Schaap <perl6 [...] mscha.org>
Download (untitled) / with headers
text/plain 749b
It's fairly rare to encounter a Rat that isn't normalized, but if you do get one, norm() doesn't normalize the numerator/denominator. nude() does, though, and actually changes the Rat (which is supposed to be immutable). Example: Show quoted text
> my $f = 1/13² + 1/26² + 1/39² + 1/78²
0.008218 Show quoted text
> say $f.numerator, '/', $f.denominator;
50/6084 Show quoted text
> my $g = $f.norm;
0.008218 Show quoted text
> say $g.numerator, '/', $g.denominator;
50/6084 Show quoted text
> say $f.nude.join('/');
25/3042 Show quoted text
> say $f.numerator, '/', $f.denominator;
25/3042 Show quoted text
> say $g.numerator, '/', $g.denominator;
25/3042 Even stranger, $g is now normalized as well. This is on Rakudo Star 2017.01, 64-bit Linux. % perl6 --version This is Rakudo version 2017.01 built on MoarVM version 2017.01 implementing Perl 6.c.
From: Michael Schaap <perl6 [...] mscha.org>
To: perl6-bugs-followup [...] perl.org
Subject: Re: [perl #130774] AutoReply: [BUG] Rat.norm() doesn't normalize, but Rat.nude() does - in place!
Date: Mon, 13 Feb 2017 15:09:12 +0100
Download (untitled) / with headers
text/plain 100b
Actually, it's not as rare as I thought: the same thing happens when you do: Show quoted text
> my $f = 1/6 + 1/6
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 364b
The avoidance of reduction is for optimization purposes. The .norm stuff is fixed now in https://github.com/rakudo/rakudo/commit/aac9efcbda and tested in https://github.com/perl6/roast/commit/7d0daf5286 However, there's a data-race in Rational.REDUCE-ME and it needs to go: https://irclog.perlgeek.de/perl6-dev/2017-02-13#i_14093035 Renaming the ticket to that.
Download (untitled) / with headers
text/plain 212b
Another issue the .REDUCE-ME thing causes: mscha │ m: say (1/2+1/2, 2/2).unique; +camelia │ rakudo-moar 9da50e: OUTPUT: «(1 1)␤» infix:<+> does not call .REDUCE-ME so the rats are different in this case


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