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.

1
2
3
4
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.

1
2
3
4
5
6
7
8
9
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.

1
2
Complex(1, 1) / 2    #=> ((1/2)+(1/2)*i)
Complex(1, 1) / 2.0  #=> (0.5+0.5i)
-@
  • References/Ruby on Rails/Ruby/Classes/Complex

-cmp â complex Instance Public methods Returns negation of the value.

2025-01-10 15:47:30
~
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.conj â complexcmp.conjugate â complex Instance Public methods Returns

2025-01-10 15:47:30
abs
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.abs â real Instance Public methods Returns the absolute part of

2025-01-10 15:47:30
rect
  • References/Ruby on Rails/Ruby/Classes/Complex

Complex.rect(real[, imag]) â complexComplex.rectangular(real[, imag]) â complex Class Public methods

2025-01-10 15:47:30
**
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp ** numeric â complex Instance Public methods Performs exponentiation

2025-01-10 15:47:30
rect 2
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.rect â arraycmp.rectangular â array Instance Public methods Returns

2025-01-10 15:47:30
magnitude
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.magnitude â real Instance Public methods Returns the absolute part of

2025-01-10 15:47:30
fdiv
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.fdiv(numeric) â complex Instance Public methods Performs division as

2025-01-10 15:47:30
to_json
  • References/Ruby on Rails/Ruby/Classes/Complex

to_json(*) Instance Public methods

2025-01-10 15:47:30
to_f
  • References/Ruby on Rails/Ruby/Classes/Complex

cmp.to_f â float Instance Public methods Returns the value as a float if

2025-01-10 15:47:30