class Complex
src
class Complex is Cool does Numeric { ... }
Represents a number in the complex plane.
Complex objects are immutable.
Adding a trailing i to a number literal makes it a Complex, for example:
2i; # same as Complex.new(0, 2);
1-2e3i; # same as Complex.new(1, -2e3);
Methods
new
proto method new(*@, *%) {*} returns Complex:D
multi method new(Real $re, Real $im) returns Complex:D
Creates a new Complex object from real and imaginary parts.
re
method re(Complex:D:) returns Real:D
Returns the real part of the complex number.
im
method im(Complex:D:) returns Real:D
Returns the imaginary part of the complex number.
isNaN
method isNaN(Complex:D:) returns Bool:D
Returns true if the real or imaginary part is NaN (not a number).
polar
method polar(Complex:D:) returns Positional:D
Returns a two-element list of the polar coordinates for this value,
ie magnitude and angle in radians.