Project

General

Profile

Bug #11162 » 0001-Update-documentation-for-CMath-library.patch

davydov_anton (Anton Davydov), 05/19/2015 11:15 PM

View differences:

ChangeLog
2015-05-20 Anton Davydov <antondavydov.o@gmail.com>
* lib/cmath.rb: [DOC] update documentation for CMath library
[ci skip]
Mon May 18 15:31:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/intern.h (rb_f_notimplement): should not respond to
lib/cmath.rb
##
# = Trigonometric and transcendental functions for complex numbers.
#
# CMath is a library that provides trigonometric and transcendental
# functions for complex numbers.
# functions for complex numbers. The functions in this module accept
# integers, floating-point numbers or complex numbers as arguments.
#
# Note that the selection of functions is similar, but not identical,
# to that in module math. The reason for having two modules is that
# some users aren’t interested in complex numbers, and perhaps don’t
# even know what they are. They would rather have Math.sqrt(-1) raise
# an exception than return a complex number.
#
# == Brief overview of complex numbers
#
# A complex number is a number that can be expressed in the form
# a + bi, where a and b are real numbers and i is the imaginary unit,
# that satisfies the equation x**2 = −1, that is, i**2 = −1. In this
# expression, a is the real part and b is the imaginary part of the
# complex number.
#
# In ruby, you can create complex object with Complex, ::rect, ::polar
# or #to_c method.
#
# Complex(1) #=> (1+0i)
# Complex.polar(2, 3) #=> (-1.9799849932008908+0.2822400161197344i)
# 3.to_c #=> (3+0i)
#
# == Usage
#
# To start using this library, simply:
# To start using this library, simply require cmath library:
#
# require "cmath"
#
# Square root of a negative number is a complex number.
# And after call any CMath function. For example:
#
# CMath.sqrt(-9) #=> 0+3.0i
# CMath.exp(Complex(0,0)) #=> 1.0+0.0i
# CMath.log10(-5.to_c) #=> (0.6989700043360187+1.3643763538418412i)
#
# CMath.sqrt(-9) #=> 0+3.0i
# == References
#
# Kahan, W: Branch cuts for complex elementary functions
# Solomentsev, E.D. (2001), "Complex number", in Hazewinkel, Michiel,
# <em>Encyclopedia of Mathematics, Springer, ISBN 978-1-55608-010-4
#
module CMath
......
##
# Math::E raised to the +z+ power
#
# 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
# CMath.exp(Complex(0,PI)) #=> -1.0+1.2246467991473532e-16i
def exp(z)
begin
if z.real?
......
end
##
# Returns the natural logarithm of Complex. If a second argument is given,
# Returns the natural logarithm of Complex. If a second argument is given,
# it will be the base of logarithm.
#
# log(Complex(0,0)) #=> -Infinity+0.0i
# CMath.log(Complex(1,4)) #=> (1.416606672028108+1.3258176636680326i)
# CMath.log(Complex(1,4), 10) #=> (0.6152244606891369+0.5757952953408879i)
def log(z, b=::Math::E)
begin
if z.real? && z >= 0 && b >= 0
......
##
# returns the base 2 logarithm of +z+
#
# CMath.log2(-1) => (0.0+4.532360141827194i)
def log2(z)
begin
if z.real? and z >= 0
......
##
# returns the base 10 logarithm of +z+
#
# CMath.log10(-1) #=> (0.0+1.3643763538418412i)
def log10(z)
begin
if z.real? and z >= 0
......
##
# 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
#
# CMath.sqrt(Complex(-1,0)) #=> 0.0+1.0i
def sqrt(z)
begin
if z.real?
......
##
# returns the principal value of the cube root of +z+
#
# CMath.cbrt(Complex(1,4)) #=> (1.449461632813119+0.6858152562177092i)
def cbrt(z)
z ** (1.0/3)
end
##
# returns the sine of +z+, where +z+ is given in radians
#
# CMath.sin(Complex(Math::PI)) #=> (1.2246467991473532e-16-0.0i)
def sin(z)
begin
if z.real?
......
##
# returns the cosine of +z+, where +z+ is given in radians
#
# CMath.cos(Complex(Math::PI)) #=> (-1.0-0.0i)
def cos(z)
begin
if z.real?
......
##
# returns the tangent of +z+, where +z+ is given in radians
#
# CMath.tan(Complex(Math::PI)) #=> (-1.2246467991473532e-16+0.0i)
def tan(z)
begin
if z.real?
......
##
# returns the hyperbolic sine of +z+, where +z+ is given in radians
#
# CMath.sinh(Complex(Math::PI)) #=> (11.548739357257746+0.0i)
def sinh(z)
begin
if z.real?
......
##
# returns the hyperbolic cosine of +z+, where +z+ is given in radians
#
# CMath.cosh(Complex(Math::PI)) #=> (11.591953275521519+0.0i)
def cosh(z)
begin
if z.real?
......
##
# returns the hyperbolic tangent of +z+, where +z+ is given in radians
#
# CMath.tanh(Complex(Math::PI)) #=> (0.99627207622075+0.0i)
def tanh(z)
begin
if z.real?
......
##
# returns the arc sine of +z+
#
# CMath.asin(Complex(Math::PI)) #=> (1.5707963267948966-1.8115262724608532i)
def asin(z)
begin
if z.real? and z >= -1 and z <= 1
......
##
# returns the arc cosine of +z+
#
# CMath.acos(Complex(Math::PI)) #=> (0.0+1.8115262724608536i)
def acos(z)
begin
if z.real? and z >= -1 and z <= 1
......
##
# returns the arc tangent of +z+
#
# CMath.atan(Complex(Math::PI)) #=> (1.2626272556789118+0.0i)
def atan(z)
begin
if z.real?
......
##
# returns the arc tangent of +y+ divided by +x+ using the signs of +y+ and
# +x+ to determine the quadrant
#
# CMath.atan2(Complex(Math::PI), 0) #=> (1.5707963267948966+0.0i)
def atan2(y,x)
begin
if y.real? and x.real?
......
##
# returns the inverse hyperbolic sine of +z+
#
# CMath.asinh(Complex(Math::PI)) #=> (1.8622957433108482+0.0i)
def asinh(z)
begin
if z.real?
......
##
# returns the inverse hyperbolic cosine of +z+
#
# CMath.acosh(Complex(Math::PI)) #=> (1.8115262724608532+0.0i)
def acosh(z)
begin
if z.real? and z >= 1
......
##
# returns the inverse hyperbolic tangent of +z+
#
# CMath.atanh(Complex(Math::PI)) #=> (0.32976531495669914-1.5707963267948966i)
def atanh(z)
begin
if z.real? and z >= -1 and z <= 1
    (1-1/1)