class Quadratic::Imag

Abstract class for Quadratic[d] (d < 0).

Instances behave like those of Complex. See #to_c for details of the complex expression.

Public Instance Methods

==(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/quadratic_number/imag.rb, line 36
def ==(other)
        if other.kind_of?(Numeric)
                self.to_c - other == 0
        else
                other == self
        end
end
real?() click to toggle source

Returns false.

# File lib/quadratic_number/imag.rb, line 18
def real?
        false
end
to_c() click to toggle source

Returns an equivalent complex. Its imaginary part is usually a Quadratic::Real.

@return [Complex]

@example

Quadratic[-3].new(1, 2)      #=> (1+2√-3)
Quadratic[-3].new(1, 2).to_c #=> (1+(0+2√3)*i)
Quadratic[-1].new(3, 4)      #=> (3+4√-1)
Quadratic[-1].new(3, 4).to_c #=> (3+4i)
# File lib/quadratic_number/imag.rb, line 64
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