Module: JBLAS::ComplexMixin

Included in:
ComplexDouble, ComplexFloat
Defined in:
lib/jblas/complex.rb

Overview

Syntactic sugar for complex numbers.

Defines the arithmetic operators *, +, -, /, and coercion such that the complex numbers interact well with the builtin numerics.

Instance Method Summary collapse

Instance Method Details

#*(o) ⇒ Object

Multiply complex values.



53
# File 'lib/jblas/complex.rb', line 53

def *(o); mul(o); end

#+(o) ⇒ Object

Add complex values.



55
# File 'lib/jblas/complex.rb', line 55

def +(o); add(o); end

#-(o) ⇒ Object

Subtract complex values.



57
# File 'lib/jblas/complex.rb', line 57

def -(o); sub(o); end

#-@Object

Negative complex values.



61
# File 'lib/jblas/complex.rb', line 61

def -@; neg; end

#/(o) ⇒ Object

Divide complex values.



59
# File 'lib/jblas/complex.rb', line 59

def /(o); div(o); end

#absObject

Get the length of the complex number



84
# File 'lib/jblas/complex.rb', line 84

def abs; JAVA_METHOD; end

#argObject

Get the angle of the complex number



87
# File 'lib/jblas/complex.rb', line 87

def arg; JAVA_METHOD; end

#coerce(o) ⇒ Object

:nodoc:



74
75
76
77
78
# File 'lib/jblas/complex.rb', line 74

def coerce(o) #:nodoc:
  unless self.class === o
    [ReversedArithmetic.new(self), o]
  end
end

#conjObject

Get the conjugate of the complex number



90
# File 'lib/jblas/complex.rb', line 90

def conj; JAVA_METHOD; end

#inspectObject

Same as to_s.



48
49
50
# File 'lib/jblas/complex.rb', line 48

def inspect
  to_s
end

#rdiv(o) ⇒ Object

Divide with swapped operands.

This means that a.rdiv(b) = b / a. This method is necessary to make coercion work.



72
# File 'lib/jblas/complex.rb', line 72

def rdiv(o); inv * o; end

#rsub(o) ⇒ Object

Subtract with swapped operands.

This means that a.rsub(b) = b - a. This method is necessary to make coercion work.



67
# File 'lib/jblas/complex.rb', line 67

def rsub(o); -self + o; end

#sqrtObject

Compute the square root



81
# File 'lib/jblas/complex.rb', line 81

def sqrt; JAVA_METHOD; end

#to_sObject

Convert to a string.



43
44
45
# File 'lib/jblas/complex.rb', line 43

def to_s
  "#{real} + #{imag}i"
end