complex.rb

Path: lib/complex.rb
Last Update: Sun Oct 12 10:45:43 +0000 2008
  complex.rb -
      $Release Version: 0.5 $
      $Revision: 1.3 $
      $Date: 1998/07/08 10:05:28 $
      by Keiju ISHITSUKA(SHL Japan Inc.)

complex.rb implements the Complex class for complex numbers. Additionally, some methods in other Numeric classes are redefined or added to allow greater interoperability with Complex numbers.

Complex numbers can be created in the following manner:

Additionally, note the following:

  • Complex::I (the mathematical constant i)
  • Numeric#im (e.g. 5.im -> 0+5i)

The following Math module methods are redefined to handle Complex arguments. They will work as normal with non-Complex arguments.

   sqrt exp cos sin tan log log10
   cosh sinh tanh acos asin atan atan2 acosh asinh atanh

Methods

Complex  

Public Instance methods

Creates a Complex number. a and b should be Numeric. The result will be a+bi.

[Source]

# File lib/complex.rb, line 90
def Complex(a, b = 0)
  if b == 0 and (a.kind_of?(Complex) or defined? Complex::Unify)
    a
  else
    Complex.new( a.real-b.imag, a.imag+b.real )
  end
end

[Validate]