1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/cmath.rb (log2, cbrt): added. [experimental]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2009-06-29 16:25:11 +00:00
parent c8b995e7ac
commit ad1d5a3c31
2 changed files with 26 additions and 2 deletions

View file

@ -1,3 +1,7 @@
Tue Jun 30 01:24:10 2009 Tadayoshi Funaba <tadf@dotrb.org>
* lib/cmath.rb (log2, cbrt): added. [experimental]
Tue Jun 30 01:19:53 2009 Tadayoshi Funaba <tadf@dotrb.org> Tue Jun 30 01:19:53 2009 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c (nucomp_expt): do not use rb_fexpt. * complex.c (nucomp_expt): do not use rb_fexpt.

View file

@ -4,8 +4,10 @@ module CMath
alias exp! exp alias exp! exp
alias log! log alias log! log
alias log2! log2
alias log10! log10 alias log10! log10
alias sqrt! sqrt alias sqrt! sqrt
alias cbrt! cbrt
alias sin! sin alias sin! sin
alias cos! cos alias cos! cos
@ -47,6 +49,14 @@ module CMath
end end
end end
def log2(z)
if z.real? and z >= 0
log2!(z)
else
log(z) / log!(2)
end
end
def log10(z) def log10(z)
if z.real? and z >= 0 if z.real? and z >= 0
log10!(z) log10!(z)
@ -74,6 +84,14 @@ module CMath
end end
end end
def cbrt(z)
if z.real? and z >= 0
cbrt!(z)
else
Complex(z) ** (1.0/3)
end
end
def sin(z) def sin(z)
if z.real? if z.real?
sin!(z) sin!(z)
@ -186,10 +204,14 @@ module CMath
module_function :exp module_function :exp
module_function :log! module_function :log!
module_function :log module_function :log
module_function :log2!
module_function :log2
module_function :log10! module_function :log10!
module_function :log10 module_function :log10
module_function :sqrt! module_function :sqrt!
module_function :sqrt module_function :sqrt
module_function :cbrt!
module_function :cbrt
module_function :sin! module_function :sin!
module_function :sin module_function :sin
@ -221,8 +243,6 @@ module CMath
module_function :atanh! module_function :atanh!
module_function :atanh module_function :atanh
module_function :log2
module_function :cbrt
module_function :frexp module_function :frexp
module_function :ldexp module_function :ldexp
module_function :hypot module_function :hypot