Class: Quadratic::Imag

Inherits:
Object
  • Object
show all
Defined in:
lib/quadratic_number/imag.rb

Overview

< Quadratic < Numeric

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/quadratic_number/imag.rb', line 22

def ==(other)
  if other.kind_of?(Numeric)
    self.to_c - other == 0
  else
    other == self
  end
end

#real?Boolean

defined by Numeric:

  • integer? #=> false

Returns:

  • (Boolean)


9
10
11
# File 'lib/quadratic_number/imag.rb', line 9

def real?
  false
end

#to_cObject

Type conversions ###



38
39
40
41
42
43
44
45
46
# File 'lib/quadratic_number/imag.rb', line 38

def to_c
  d = self.class::D
  if d == -1
    Complex.rect(@a, @b)
  else
    rev_class = Quadratic[-d]
    Complex.rect(@a, rev_class.new(0, @b))
  end
end