mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/cmath.rb: Improve documentation. Patch by Jason Dew.
[Ruby 1.9 - Feature #4717] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
babda328c0
commit
6e1b572364
2 changed files with 48 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed May 18 04:53:41 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/cmath.rb: Improve documentation. Patch by Jason Dew.
|
||||||
|
[Ruby 1.9 - Feature #4717]
|
||||||
|
|
||||||
Wed May 18 04:50:24 2011 Eric Hodel <drbrain@segment7.net>
|
Wed May 18 04:50:24 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/net/ftp.rb: Improve documentation. Patch by Vincent Batts.
|
* lib/net/ftp.rb: Improve documentation. Patch by Vincent Batts.
|
||||||
|
|
43
lib/cmath.rb
43
lib/cmath.rb
|
@ -1,3 +1,6 @@
|
||||||
|
##
|
||||||
|
# Math functions for Complex numbers
|
||||||
|
|
||||||
module CMath
|
module CMath
|
||||||
|
|
||||||
include Math
|
include Math
|
||||||
|
@ -26,6 +29,8 @@ module CMath
|
||||||
alias acosh! acosh
|
alias acosh! acosh
|
||||||
alias atanh! atanh
|
alias atanh! atanh
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the value of e raised to the +z+ power
|
||||||
def exp(z)
|
def exp(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
exp!(z)
|
exp!(z)
|
||||||
|
@ -36,6 +41,9 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the log of the first argument with the base
|
||||||
|
# optionally specified as the second argument
|
||||||
def log(*args)
|
def log(*args)
|
||||||
z, b = args
|
z, b = args
|
||||||
if z.real? and z >= 0 and (b.nil? or b >= 0)
|
if z.real? and z >= 0 and (b.nil? or b >= 0)
|
||||||
|
@ -49,6 +57,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the log base 2 of +z+
|
||||||
def log2(z)
|
def log2(z)
|
||||||
if z.real? and z >= 0
|
if z.real? and z >= 0
|
||||||
log2!(z)
|
log2!(z)
|
||||||
|
@ -57,6 +67,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the log base 10 of +z+
|
||||||
def log10(z)
|
def log10(z)
|
||||||
if z.real? and z >= 0
|
if z.real? and z >= 0
|
||||||
log10!(z)
|
log10!(z)
|
||||||
|
@ -65,6 +77,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the square root of +z+
|
||||||
def sqrt(z)
|
def sqrt(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
if z < 0
|
if z < 0
|
||||||
|
@ -84,6 +98,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the cube root of +z+
|
||||||
def cbrt(z)
|
def cbrt(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
cbrt!(z)
|
cbrt!(z)
|
||||||
|
@ -92,6 +108,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the sine of +z+, where +z+ is given in radians
|
||||||
def sin(z)
|
def sin(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
sin!(z)
|
sin!(z)
|
||||||
|
@ -101,6 +119,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the cosine of +z+, where +z+ is given in radians
|
||||||
def cos(z)
|
def cos(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
cos!(z)
|
cos!(z)
|
||||||
|
@ -110,6 +130,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the tangent of +z+, where +z+ is given in radians
|
||||||
def tan(z)
|
def tan(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
tan!(z)
|
tan!(z)
|
||||||
|
@ -118,6 +140,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the hyperbolic sine of +z+
|
||||||
def sinh(z)
|
def sinh(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
sinh!(z)
|
sinh!(z)
|
||||||
|
@ -127,6 +151,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the hyperbolic cosine of +z+
|
||||||
def cosh(z)
|
def cosh(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
cosh!(z)
|
cosh!(z)
|
||||||
|
@ -136,6 +162,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the hyperbolic tangent of +z+
|
||||||
def tanh(z)
|
def tanh(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
tanh!(z)
|
tanh!(z)
|
||||||
|
@ -144,6 +172,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the arc sine of +z+
|
||||||
def asin(z)
|
def asin(z)
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
asin!(z)
|
asin!(z)
|
||||||
|
@ -152,6 +182,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the arc cosine of +z+
|
||||||
def acos(z)
|
def acos(z)
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
acos!(z)
|
acos!(z)
|
||||||
|
@ -160,6 +192,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the arc tangent of +z+
|
||||||
def atan(z)
|
def atan(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
atan!(z)
|
atan!(z)
|
||||||
|
@ -168,6 +202,9 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the arc tangent of +y+ / +x+ using the signs
|
||||||
|
# of +y+ and +x+ to determine the quadrant
|
||||||
def atan2(y,x)
|
def atan2(y,x)
|
||||||
if y.real? and x.real?
|
if y.real? and x.real?
|
||||||
atan2!(y,x)
|
atan2!(y,x)
|
||||||
|
@ -176,6 +213,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the inverse hyperbolic sine of +z+
|
||||||
def asinh(z)
|
def asinh(z)
|
||||||
if z.real?
|
if z.real?
|
||||||
asinh!(z)
|
asinh!(z)
|
||||||
|
@ -184,6 +223,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the inverse hyperbolic cosine of +z+
|
||||||
def acosh(z)
|
def acosh(z)
|
||||||
if z.real? and z >= 1
|
if z.real? and z >= 1
|
||||||
acosh!(z)
|
acosh!(z)
|
||||||
|
@ -192,6 +233,8 @@ module CMath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# returns the inverse hyperbolic tangent of +z+
|
||||||
def atanh(z)
|
def atanh(z)
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
atanh!(z)
|
atanh!(z)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue