Represents a number in the complex plane.

Complex objects are immutable.

# Operators§

## postfix i§

Adding a trailing `i` to a number literal makes it a Complex, for example:

# Methods§

## method new§

Creates a new `Complex` object from real and imaginary parts.

When created without arguments, both parts are considered to be zero.

## method re§

Returns the real part of the complex number.

## method im§

Returns the imaginary part of the complex number.

## method reals§

Returns a two-element list containing the real and imaginary parts for this value.

## method isNaN§

Returns true if the real or imaginary part is `NaN` (not a number).

## method polar§

Returns a two-element list of the polar coordinates for this value, i.e. magnitude and angle in radians.

## method floor§

Returns `self.re.floor + self.im.floor`. That is, each of the real and imaginary parts is rounded to the highest integer not greater than the value of that part.

## method ceiling§

Returns `self.re.ceiling + self.im.ceiling`. That is, each of the real and imaginary parts is rounded to the lowest integer not less than the value of that part.

## routine sign§

Returns `0i` if the absolute value of the complex number is 0. Otherwise returns the complex number divided by its absolute value (the unit complex number in the same direction as \$z).

Available as of 6.e language version (early implementation exists in Rakudo compiler 2023.02+).

## method round§

With no arguments, rounds both the real and imaginary parts to the nearest integer and returns a new `Complex` number. If `\$scale` is given, rounds both parts of the invocant to the nearest multiple of `\$scale`. Uses the same algorithm as Real.round on each part of the number.

## method truncate§

Removes the fractional part of both the real and imaginary parts of the number, using Real.truncate, and returns the result as a new `Complex`.

## routine abs§

Returns the absolute value of the invocant (or the argument in sub form). For a given complex number `\$z` the absolute value `|\$z|` is defined as `sqrt(\$z.re * \$z.re + \$z.im * \$z.im)`.

## method conj§

Returns the complex conjugate of the invocant (that is, the number with the sign of the imaginary part negated).

## method sqrt§

Returns the complex square root of the invocant, i.e. the root where the real part is ≥ 0 and the imaginary part has the same sign as the imaginary part of the invocant.

## method gist§

Returns a string representation of the form "1+2i", without internal spaces. (Str coercion also returns this.)

## method raku§

Returns an implementation-specific string that produces an equivalent object when given to EVAL.

## method Real§

Coerces the invocant to Num. If the imaginary part isn't approximately zero, coercion fails with `X::Numeric::Real`.

The `:D` variant returns the result of that coercion. The `:U` variant issues a warning about using an uninitialized value in numeric context and then returns value `0e0`.

## sub infix:<**>§

The exponentiation operator coerces the second argument to Complex and calculates the left-hand-side raised to the power of the right-hand side. Since 6.d, either argument can be equal to zero.