Index of Classes & Methods in cmath: Ruby Standard Library Documentation (Ruby 2.2.3)

- Home
- Core 2.2.3
- Std-lib 2.2.3
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

#### Ruby 2.2.3

New to Ruby? You may find these links helpful: syntax, control expressions, assignment, methods, modules + classes, and operator precedence.

# Trigonometric and transcendental functions for complex numbers.¶ ↑

CMath is a library that provides trigonometric and transcendental 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.

## Usage¶ ↑

To start using this library, simply require cmath library:

    require "cmath"

And after call any CMath function. For example:

    CMath.sqrt(-9)          #=> 0+3.0i
    CMath.exp(0 + 0i)       #=> 1.0+0.0i
    CMath.log10(-5.to_c)    #=> (0.6989700043360187+1.3643763538418412i)

For more information you can see Complec class.

Classes

M CMath

Methods

::acos (CMath)

::acos! (CMath)

::acosh (CMath)

::acosh! (CMath)

::asin (CMath)

::asin! (CMath)

::asinh (CMath)

::asinh! (CMath)

::atan (CMath)

::atan! (CMath)

::atan2 (CMath)

::atan2! (CMath)

::atanh (CMath)

::atanh! (CMath)

::cbrt (CMath)

::cbrt! (CMath)

::cos (CMath)

::cos! (CMath)

::cosh (CMath)

::cosh! (CMath)

::exp (CMath)

::exp! (CMath)

::log (CMath)

::log! (CMath)

::log10 (CMath)

::log10! (CMath)

::log2 (CMath)

::log2! (CMath)

::sin (CMath)

::sin! (CMath)

::sinh (CMath)

::sinh! (CMath)

::sqrt (CMath)

::sqrt! (CMath)

::tan (CMath)

::tan! (CMath)

::tanh (CMath)

::tanh! (CMath)