September 2017
Beginner
402 pages
9h 52m
English
In Perl 6, there is the Complex built-in type to present complex numbers.
Complex numbers have two parts, real and imaginary, and use the following syntax:
my $x = 3+4i;my $y = -5i;
It is not necessary to explicitly spell out the real part, but the output always contains it:
say $x; # 3+4isay $y; # -0-5isay $z; # 0+1i
An alternative way to create a Complex number is to call a constructor (we will talk about constructors in Chapter 8, Object-Oriented Programming), as follows:
my $n = Complex.new(4, 5);say $n; # 4+5i
Read now
Unlock full access