Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/complex.rb
Overview
Numeric is a built-in class on which Fixnum, Bignum, etc., are based. Here some methods are added so that all number types can be treated to some extent as Complex numbers.
Direct Known Subclasses
Instance Method Summary collapse
-
#arg ⇒ Object
(also: #angle)
See Complex#arg.
-
#conjugate ⇒ Object
(also: #conj)
See Complex#conjugate (short answer: returns self).
-
#im ⇒ Object
Returns a Complex number
(0,self)
. -
#image ⇒ Object
(also: #imag)
The imaginary part of a complex number, i.e.
-
#polar ⇒ Object
See Complex#polar.
-
#real ⇒ Object
The real part of a complex number, i.e.
Instance Method Details
#arg ⇒ Object Also known as: angle
See Complex#arg.
60 61 62 63 64 65 66 67 68 |
# File 'lib/complex.rb', line 60 def arg if self > 0 || (self == 0 && self.to_s != '-0.0') # This string comparison stuff is gross. Better way? return 0 elsif self.to_f.nan? return self else return Math::PI end end |
#conjugate ⇒ Object Also known as: conj
See Complex#conjugate (short answer: returns self).
81 82 83 |
# File 'lib/complex.rb', line 81 def conjugate self end |
#im ⇒ Object
Returns a Complex number (0,self)
.
38 39 40 |
# File 'lib/complex.rb', line 38 def im Complex(0, self) end |
#image ⇒ Object Also known as: imag
The imaginary part of a complex number, i.e. 0.
52 53 54 |
# File 'lib/complex.rb', line 52 def image 0 end |
#polar ⇒ Object
See Complex#polar.
74 75 76 |
# File 'lib/complex.rb', line 74 def polar return abs, arg end |
#real ⇒ Object
The real part of a complex number, i.e. self.
45 46 47 |
# File 'lib/complex.rb', line 45 def real self end |