summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-29 16:25:11 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-29 16:25:11 +0000
commit183a9861c13b446704c51dc76aa463c86c8a7d11 (patch)
treeeada22a1c101245a619ede954f2b45cb9b0a900c /lib
parentb6fa066b8f617f252177ece93903b02773467d3e (diff)
downloadruby-183a9861c13b446704c51dc76aa463c86c8a7d11.tar.gz
ruby-183a9861c13b446704c51dc76aa463c86c8a7d11.tar.xz
ruby-183a9861c13b446704c51dc76aa463c86c8a7d11.zip
* lib/cmath.rb (log2, cbrt): added. [experimental]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/cmath.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/cmath.rb b/lib/cmath.rb
index 6b47e70a1..c4b14e3ef 100644
--- a/lib/cmath.rb
+++ b/lib/cmath.rb
@@ -4,8 +4,10 @@ module CMath
alias exp! exp
alias log! log
+ alias log2! log2
alias log10! log10
alias sqrt! sqrt
+ alias cbrt! cbrt
alias sin! sin
alias cos! cos
@@ -47,6 +49,14 @@ module CMath
end
end
+ def log2(z)
+ if z.real? and z >= 0
+ log2!(z)
+ else
+ log(z) / log!(2)
+ end
+ end
+
def log10(z)
if z.real? and z >= 0
log10!(z)
@@ -74,6 +84,14 @@ module CMath
end
end
+ def cbrt(z)
+ if z.real? and z >= 0
+ cbrt!(z)
+ else
+ Complex(z) ** (1.0/3)
+ end
+ end
+
def sin(z)
if z.real?
sin!(z)
@@ -186,10 +204,14 @@ module CMath
module_function :exp
module_function :log!
module_function :log
+ module_function :log2!
+ module_function :log2
module_function :log10!
module_function :log10
module_function :sqrt!
module_function :sqrt
+ module_function :cbrt!
+ module_function :cbrt
module_function :sin!
module_function :sin
@@ -221,8 +243,6 @@ module CMath
module_function :atanh!
module_function :atanh
- module_function :log2
- module_function :cbrt
module_function :frexp
module_function :ldexp
module_function :hypot