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

Optional $base argument for log() #1382

Closed
p6rt opened this issue Oct 29, 2009 · 4 comments
Closed

Optional $base argument for log() #1382

p6rt opened this issue Oct 29, 2009 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 29, 2009

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

Searchable as RT70105$

@p6rt
Copy link
Author

p6rt commented Oct 29, 2009

From @Kodiologist

This is a simplistic implementation of the optional $base argument to
the various functions and methods named log(). It computes the logarithm
of an arbitrary base as the quotient of two natural logs. With these
additions, Rakudo can pass tests 3 and 4 in t/spec/S32-num/log.t.

@p6rt
Copy link
Author

p6rt commented Oct 29, 2009

From @Kodiologist

log.diff
diff --git a/src/setting/Any-num.pm b/src/setting/Any-num.pm
index 193512c..787845f 100644
--- a/src/setting/Any-num.pm
+++ b/src/setting/Any-num.pm
@@ -79,6 +79,10 @@ class Any is also {
         $.Num.log();
     }
 
+    multi method log($base) {
+        $.Num.log($base);
+    }
+
     our multi method !from-radians($base) {
         given $base {
             when /:i ^d/ { self * 180/pi  }    # Convert to degrees.
@@ -194,6 +198,7 @@ class Any is also {
 multi sub abs($x) { (+$x).abs() }
 multi sub exp($x) { $x.Num.exp() }
 multi sub log($x) { $x.Num.log() }
+multi sub log($x, $base) { $x.Num.log($base) }
 multi sub log10($x) { $x.Num.log10 }
 
 # jnthn says that we should have both the multi sub declaration and the proto.
diff --git a/src/setting/Complex.pm b/src/setting/Complex.pm
index 791a816..70e93fa 100644
--- a/src/setting/Complex.pm
+++ b/src/setting/Complex.pm
@@ -147,6 +147,10 @@ class Complex {
         }
     }
 
+    multi method log($base) {
+        $.log / $base.log;
+    }
+
     multi method log10() {
         $.log / 10.log;
     }
@@ -304,6 +308,10 @@ multi sub log(Complex $x) {
     $x.log()
 }
 
+multi sub log(Complex $x, $base) {
+    $x.log($base)
+}
+
 multi sub log10(Complex $x) {
     $x.log10;
 }
diff --git a/src/setting/Num.pm b/src/setting/Num.pm
index e88d587..0360e86 100644
--- a/src/setting/Num.pm
+++ b/src/setting/Num.pm
@@ -238,6 +238,10 @@ class Num is also {
         }
     }
 
+    multi method log($base) {
+        $.log / $base.log
+    }
+
     our method log10 {
         Q:PIR {
             $N0 = self

@p6rt
Copy link
Author

p6rt commented Mar 30, 2010

From @moritz

I don't know if your patch ever got applied, but we do have a log()
function and method with an optional base argument right now.

Thank you for your patch,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 30, 2010

@moritz - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed Mar 30, 2010
@p6rt p6rt added the patch 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