Type:
Class
Constants:
I : f_complex_new_bang2(rb_cComplex, ZERO, ONE)

The imaginary unit.

A complex number can be represented as a paired real number with imaginary unit; a+bi. Where a is real part, b is imaginary part and i is imaginary unit. Real a equals complex a+0i mathematically.

In ruby, you can create complex object with Complex, ::rect, ::polar or #to_c method.

Complex(1)           #=> (1+0i)
Complex(2, 3)        #=> (2+3i)
Complex.polar(2, 3)  #=> (-1.9799849932008908+0.2822400161197344i)
3.to_c               #=> (3+0i)

You can also create complex object from floating-point numbers or strings.

Complex(0.3)         #=> (0.3+0i)
Complex('0.3-0.5i')  #=> (0.3-0.5i)
Complex('2/3+3/4i')  #=> ((2/3)+(3/4)*i)
Complex('1@2')       #=> (-0.4161468365471424+0.9092974268256817i)

0.3.to_c             #=> (0.3+0i)
'0.3-0.5i'.to_c      #=> (0.3-0.5i)
'2/3+3/4i'.to_c      #=> ((2/3)+(3/4)*i)
'1@2'.to_c           #=> (-0.4161468365471424+0.9092974268256817i)

A complex object is either an exact or an inexact number.

Complex(1, 1) / 2    #=> ((1/2)+(1/2)*i)
Complex(1, 1) / 2.0  #=> (0.5+0.5i)
inspect

cmp.inspect â string Instance Public methods Returns the value as a string

2015-04-01 14:23:32
polar

Complex.polar(abs[, arg]) â complex Class Public methods Returns a complex

2015-04-01 12:53:40
to_i

cmp.to_i â integer Instance Public methods Returns the value as an integer

2015-04-01 15:22:47
polar 2

cmp.polar â array Instance Public methods Returns an array; [cmp.abs, cmp

2015-04-01 14:37:11
conjugate

cmp.conjugate â complex Instance Public methods Returns the complex conjugate

2015-04-01 13:59:58
imaginary

cmp.imaginary â real Instance Public methods Returns the imaginary part.

2015-04-01 14:18:47
arg

cmp.arg â float Instance Public methods Returns the angle part of its polar

2015-04-01 13:46:25
quo

cmp / numeric â complexcmp.quo(numeric) â complex Instance Public methods

2015-04-01 14:42:21
/ 2

cmp / numeric â complexcmp.quo(numeric) â complex Instance Public methods

2015-04-01 13:16:35
as_json

as_json(*) Instance Public methods

2015-04-01 13:49:38