Class: Complex
- Inherits:
-
Numeric
- Object
- Numeric
- Complex
- Defined in:
- lib/bigdecimal/util.rb,
sig/big_decimal.rbs,
sig/big_decimal_util.rbs
Instance Method Summary collapse
-
#* ⇒ Object
Returns the product of `self` and `numeric`:.
-
#+ ⇒ Object
Returns the sum of `self` and `numeric`:.
-
#- ⇒ Object
Returns the difference of `self` and `numeric`:.
-
#/ ⇒ Object
Returns the quotient of `self` and `numeric`:.
-
#to_d(precision = 0) ⇒ BigDecimal
Returns the value as a BigDecimal.
Instance Method Details
#*(arg0) ⇒ Complex #* ⇒ void
Returns the product of self and numeric:
Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
Complex.rect(900) * Complex.rect(1) # => (900+0i)
Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
Complex.rect(9, 8) * 4 # => (36+32i)
Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
1472 1473 |
# File 'sig/big_decimal.rbs', line 1472 def *: (BigDecimal) -> Complex | ... |
#+(arg0) ⇒ Complex #+ ⇒ void
Returns the sum of self and numeric:
Complex.rect(2, 3) + Complex.rect(2, 3) # => (4+6i)
Complex.rect(900) + Complex.rect(1) # => (901+0i)
Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
Complex.rect(9, 8) + 4 # => (13+8i)
Complex.rect(20, 9) + 9.8 # => (29.8+9i)
1487 1488 |
# File 'sig/big_decimal.rbs', line 1487 def +: (BigDecimal) -> Complex | ... |
#-(arg0) ⇒ Complex #- ⇒ void
Returns the difference of self and numeric:
Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
Complex.rect(900) - Complex.rect(1) # => (899+0i)
Complex.rect(-2, 9) - Complex.rect(-9, 2) # => (7+7i)
Complex.rect(9, 8) - 4 # => (5+8i)
Complex.rect(20, 9) - 9.8 # => (10.2+9i)
1502 1503 |
# File 'sig/big_decimal.rbs', line 1502 def -: (BigDecimal) -> Complex | ... |
#/(arg0) ⇒ Complex #/ ⇒ void
Returns the quotient of self and numeric:
Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
Complex.rect(900) / Complex.rect(1) # => (900+0i)
Complex.rect(-2, 9) / Complex.rect(-9, 2) # => ((36/85)-(77/85)*i)
Complex.rect(9, 8) / 4 # => ((9/4)+2i)
Complex.rect(20, 9) / 9.8 # => (2.0408163265306123+0.9183673469387754i)
1457 1458 |
# File 'sig/big_decimal.rbs', line 1457 def /: (BigDecimal) -> Complex | ... |
#to_d(precision = 0) ⇒ BigDecimal
Returns the value as a BigDecimal. If the imaginary part is not 0, an error
is raised
The precision parameter is used to determine the number of significant
digits for the result. When precision is set to 0, the number of digits to
represent the float being converted is determined automatically. The default
precision is 0.
require 'bigdecimal'
require 'bigdecimal/util'
Complex(0.1234567, 0).to_d(4) # => 0.1235e0
Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
Complex(1, 1).to_d # raises ArgumentError
See also Kernel.BigDecimal.
164 165 166 167 168 |
# File 'lib/bigdecimal/util.rb', line 164 def to_d(precision=0) BigDecimal(self) unless self.imag.zero? # to raise error BigDecimal(self.real, precision) end |