New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement 'roots' from S29 #143
Comments
From @pmichaudI've just removed S29-num/roots.t from spectest_regression, If someone cares to write a working 'roots' function for Rakudo, Thanks! Pm |
From @moritzOn Sun Jun 22 10:04:48 2008, pmichaud wrote:
Not quite working, but I attached two Perl 6 implementation of roots() - If somebody feels like converting that to PIR, do that. If not, we'll Cheers, |
From @moritz |
The RT System itself - Status changed from 'new' to 'open' |
From @azawawiHi moritz, After looking at the code that you provided, i found that you used /ahmad On Wed Jul 09 09:12:28 2008, moritz wrote:
|
From @azawawiThis is roots_reduced.pl in PIR. It passes only 1 test in t/spec/S29- ./ahmad & |
From @azawawirt56226.patchIndex: src/builtins/any-num.pir
===================================================================
--- src/builtins/any-num.pir (revision 31763)
+++ src/builtins/any-num.pir (working copy)
@@ -21,7 +21,7 @@
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('abs cis int log chr polar sqrt truncate unpolar', 'from'=>$P0)
+ '!EXPORT'('abs cis int log chr polar sqrt truncate unpolar roots', 'from'=>$P0)
## pre-seed a random number generator
$P0 = new 'Random'
@@ -89,11 +89,46 @@
.namespace ['Any']
.sub 'polar' :method :multi(_)
- $N0 = self
- .return 'list'($N0, 0)
+ .local num real, angle
+ real = self
+ angle = atan 0, real
+ .return 'list'(real, angle)
.end
+=item roots
+=cut
+.sub 'roots' :method :multi(_)
+ .param int n
+ .local num x, mag, angle, abs, twoPI
+ .local pmc retv
+ N1 = pi()
+ N1 *= 2
+ twoPI = N1
+ x = self
+ P1 = 'polar'(x)
+ mag = P1[0]
+ angle = P1[1]
+ unless angle < 0 goto skip
+ angle += twoPI
+ skip:
+ $N0 = 1 / n
+ abs = mag ** $N0
+ P1 = new 'List'
+ retv = P1
+ I1 = 0
+ loop:
+ N1 = twoPI * I1
+ N1 += angle
+ N1 /= n
+ P1 = 'unpolar'(abs, N1)
+ retv.push(P1)
+ I1 += 1
+ if I1 < n goto loop
+ done:
+ .return (retv)
+.end
+
=item rand()
=cut
|
From @jnthnThanks to a patch from dukeleto++, roots is now implemented. Resolving |
@jnthn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#56226 (status was 'resolved')
Searchable as RT56226$
The text was updated successfully, but these errors were encountered: