Skip to content
instance method

Complex#+

(::BigDecimal) -> ::Complex
(::Numeric) -> ::Complex
self + other → numeric

Returns the sum of self and other:

Example
Complex(1, 2) + 0  # => (1+2i)
Complex(1, 2) + 1  # => (2+2i)
Complex(1, 2) + -1 # => (0+2i)

Complex(1, 2) + 1.0  # => (2.0+2i)

Complex(1, 2) + Complex(2, 1)     # => (3+3i)
Complex(1, 2) + Complex(2.0, 1.0) # => (3.0+3.0i)

Complex(1, 2) + Rational(1, 1) # => ((2/1)+2i)
Complex(1, 2) + Rational(1, 2) # => ((3/2)+2i)

For a computation involving Floats, the result may be inexact (see Float#+):

Example
Complex(1, 2) + 3.14 # => (4.140000000000001+2i)
See also #** #- #* #-@ also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0