Name

Complex — Complex number class

Synopsis

When this library is loaded with require, the ability of the Math module is expanded to handle complex numbers.

Required Library

require ‘complex’

Inherited Class

Numeric

Class Methods

Complex(r [, i=0])
Complex::new(r [, i=0])

Creates a complex number object. The former is recommended.

Instance Methods

c.abs

Returns the absolute value of the complex number c.

c.abs2

Returns the square of the absolute value of the complex number c.

c.arg

Returns the argument of the complex number c.

c.conjugate

Returns the conjugate of the complex number c.

c.image

Returns the imaginary part of the complex number c. The Complex library adds the image method to the Numeric class.

c.polar

Returns the array arr[c.abs, c.arg].

c.real

Returns the real part of the complex number c. The Complex library adds the real method to the Numeric class.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.