官术网_书友最值得收藏!

Complex numbers

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+4i
say $y; # -0-5i
say $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
主站蜘蛛池模板: 会理县| 灌南县| 美姑县| 平凉市| 遵义市| 昌江| 定日县| 佳木斯市| 象州县| 尤溪县| 兰西县| 胶州市| 西乌| 冷水江市| 宜兰县| 连城县| 江油市| 繁昌县| 徐州市| 华安县| 永嘉县| 巢湖市| 连平县| 武威市| 大荔县| 高台县| 青神县| 瑞昌市| 延吉市| 沁水县| 宝坻区| 海晏县| 翁牛特旗| 奈曼旗| 出国| 措美县| 望奎县| 定日县| 晋江市| 区。| 柘荣县|