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
-
#*(o) ⇒ Object
Multiply complex values.
-
#+(o) ⇒ Object
Add complex values.
-
#-(o) ⇒ Object
Subtract complex values.
-
#-@ ⇒ Object
Negative complex values.
-
#/(o) ⇒ Object
Divide complex values.
-
#abs ⇒ Object
Get the length of the complex number.
-
#arg ⇒ Object
Get the angle of the complex number.
-
#coerce(o) ⇒ Object
:nodoc:.
-
#conj ⇒ Object
Get the conjugate of the complex number.
-
#inspect ⇒ Object
Same as to_s.
-
#rdiv(o) ⇒ Object
Divide with swapped operands.
-
#rsub(o) ⇒ Object
Subtract with swapped operands.
-
#sqrt ⇒ Object
Compute the square root.
-
#to_s ⇒ Object
Convert to a string.
Instance Method Details
#*(o) ⇒ Object
Multiply complex values.
53 |
# File 'lib/jblas/complex.rb', line 53 def *(o); mul(o); end |
#-(o) ⇒ Object
Subtract complex values.
57 |
# File 'lib/jblas/complex.rb', line 57 def -(o); sub(o); end |
#/(o) ⇒ Object
Divide complex values.
59 |
# File 'lib/jblas/complex.rb', line 59 def /(o); div(o); end |
#abs ⇒ Object
Get the length of the complex number
84 |
# File 'lib/jblas/complex.rb', line 84 def abs; JAVA_METHOD; end |
#arg ⇒ Object
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 |
#conj ⇒ Object
Get the conjugate of the complex number
90 |
# File 'lib/jblas/complex.rb', line 90 def conj; JAVA_METHOD; end |
#inspect ⇒ Object
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 |
#sqrt ⇒ Object
Compute the square root
81 |
# File 'lib/jblas/complex.rb', line 81 def sqrt; JAVA_METHOD; end |
#to_s ⇒ Object
Convert to a string.
43 44 45 |
# File 'lib/jblas/complex.rb', line 43 def to_s "#{real} + #{imag}i" end |