Project

General

Profile

Bug #4727 » 0002-cmath-doc.patch

method doc and updated module doc - sz (Sandor Szücs), 05/18/2011 01:52 AM

View differences:

lib/cmath.rb
# This module provides access to mathematical functions for complex
# numbers.
#
# Example
# # Square root of a negative number is a complex number.
##
# = CMath
#
# CMath is a library that provides trigonometric and transcendental
# functions for complex numbers.
#
# == Usage
#
# To start using this library, simply:
#
# require "cmath"
#
# Square root of a negative number is a complex number.
#
# CMath.sqrt(-9) #=> 0+3.0i
#
module CMath
......
alias acosh! acosh
alias atanh! atanh
# Returns e**z.
# exp(Complex(0,0)) #=> 1.0+0.0i
# exp(Complex(0,PI)) #=> -1.0+1.2246467991473532e-16i
# exp(Complex(0,PI/2.0)) #=> 6.123233995736766e-17+1.0i
def exp(z)
if z.real?
exp!(z)
......
end
end
# Returns the natural logarithm of Complex. If additional second
# argument is given, it will be the base of logarithm.
# log(Complex(0,0)) #=> -Infinity+0.0i
def log(*args)
z, b = args
if z.real? and z >= 0 and (b.nil? or b >= 0)
......
end
end
# Returns the base 2 logarithm of Complex.
def log2(z)
if z.real? and z >= 0
log2!(z)
......
end
end
# Returns the base 10 logarithm of Complex.
def log10(z)
if z.real? and z >= 0
log10!(z)
......
end
end
# Returns the non-negative square root of Complex.
# sqrt(-1) #=> 0+1.0i
# sqrt(Complex(-1,0)) #=> 0.0+1.0i
# sqrt(Complex(0,8)) #=> 2.0+2.0i
def sqrt(z)
if z.real?
if z < 0
......
end
end
# Returns the cube root of a Complex.
def cbrt(z)
if z.real?
cbrt!(z)
......
end
end
# Computes the sine of z (expressed in radians).
def sin(z)
if z.real?
sin!(z)
......
end
end
# Computes the cosine of z (expressed in radians).
def cos(z)
if z.real?
cos!(z)
......
end
end
# Returns the tangent of z (expressed in radians).
def tan(z)
if z.real?
tan!(z)
......
end
end
# Computes the hyperbolic sine of z (expressed in radians).
def sinh(z)
if z.real?
sinh!(z)
......
end
end
# Computes the hyperbolic cosine of z (expressed in radians).
def cosh(z)
if z.real?
cosh!(z)
......
end
end
# Computes the hyperbolic tangent of z (expressed in radians).
def tanh(z)
if z.real?
tanh!(z)
......
end
end
# Computes the arc sine of z.
def asin(z)
if z.real? and z >= -1 and z <= 1
asin!(z)
......
end
end
# Computes the arc cosine of z.
def acos(z)
if z.real? and z >= -1 and z <= 1
acos!(z)
......
end
end
# Computes the arc tangent of z.
def atan(z)
if z.real?
atan!(z)
......
end
end
# Computes the arc tangent given y and x.
def atan2(y,x)
if y.real? and x.real?
atan2!(y,x)
......
end
end
# Computes the inverse hyperbolic sine of z.
def asinh(z)
if z.real?
asinh!(z)
......
end
end
# Computes the inverse hyperbolic cosine of z.
def acosh(z)
if z.real? and z >= 1
acosh!(z)
......
end
end
# Computes the inverse hyperbolic tangent of z.
def atanh(z)
if z.real? and z >= -1 and z <= 1
atanh!(z)
(2-2/2)