perl6/doc/lib/Complex

doc src
(title) class Complex
    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

(head2) 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.
(head2) re
    method re(Complex:D:) returns Real:D

 
Returns the real part of the complex number.
(head2) im
    method im(Complex:D:) returns Real:D

 
Returns the imaginary part of the complex number.
(head2) isNaN
    method isNaN(Complex:D:) returns Bool:D

 
Returns true if the real or imaginary part is NaN (not a number).
(head2) 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.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: