Skip to content
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

Closed
p6rt opened this issue Jun 22, 2008 · 10 comments
Closed

implement 'roots' from S29 #143

p6rt opened this issue Jun 22, 2008 · 10 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 22, 2008

Migrated from rt.perl.org#56226 (status was 'resolved')

Searchable as RT56226$

@p6rt
Copy link
Author

p6rt commented Jun 22, 2008

From @pmichaud

I've just removed S29-num/roots.t from spectest_regression,
since all of the tests were being skipped.

If someone cares to write a working 'roots' function for Rakudo,
then we can add it back. :-)

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Jul 9, 2008

From @moritz

On Sun Jun 22 10​:04​:48 2008, pmichaud wrote​:

I've just removed S29-num/roots.t from spectest_regression,
since all of the tests were being skipped.

If someone cares to write a working 'roots' function for Rakudo,
then we can add it back. :-)

Not quite working, but I attached two Perl 6 implementation of roots() -
one shiny, lazy that doesn't work with current rakudo, and one stripped
down, ugly that rakudo parses. But it can't execute it yet, because it
relies on Num.polar, which isn't implemented yet.

If somebody feels like converting that to PIR, do that. If not, we'll
have to wait for runtime in Perl 6.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jul 9, 2008

From @moritz

roots.pl

@p6rt
Copy link
Author

p6rt commented Jul 9, 2008

From @moritz

roots_reduced.pl

@p6rt
Copy link
Author

p6rt commented Jul 9, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 7, 2008

From @azawawi

Hi moritz,

After looking at the code that you provided, i found that you used
x.polar(y) in @​result. i think you meant x.unpolar(y). Am i missing
something here?

/ahmad

On Wed Jul 09 09​:12​:28 2008, moritz wrote​:

On Sun Jun 22 10​:04​:48 2008, pmichaud wrote​:

I've just removed S29-num/roots.t from spectest_regression,
since all of the tests were being skipped.

If someone cares to write a working 'roots' function for Rakudo,
then we can add it back. :-)

Not quite working, but I attached two Perl 6 implementation of roots()
-
one shiny, lazy that doesn't work with current rakudo, and one
stripped
down, ugly that rakudo parses. But it can't execute it yet, because it
relies on Num.polar, which isn't implemented yet.

If somebody feels like converting that to PIR, do that. If not, we'll
have to wait for runtime in Perl 6.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Oct 7, 2008

From @azawawi

This is roots_reduced.pl in PIR. It passes only 1 test in t/spec/S29-
num/roots.t

./ahmad &

@p6rt
Copy link
Author

p6rt commented Oct 7, 2008

From @azawawi

rt56226.patch
Index: 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

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

From @jnthn

Thanks to a patch from dukeleto++, roots is now implemented. Resolving
ticket.

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 25, 2009
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant