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

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
主站蜘蛛池模板: 旬邑县| 聂荣县| 南靖县| 石泉县| 临桂县| 鄄城县| 临海市| 吉木萨尔县| 家居| 花莲市| 巴塘县| 大宁县| 定陶县| 聂荣县| 靖边县| 阜阳市| 沿河| 安乡县| 阿瓦提县| 松桃| 上栗县| 巴楚县| 藁城市| 浏阳市| 丹棱县| 新平| 南充市| 涪陵区| 罗平县| 高台县| 丰台区| 姜堰市| 伊金霍洛旗| 海宁市| 屏山县| 瑞金市| 泾阳县| 南阳市| 淮滨县| 东海县| 台北县|