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

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
主站蜘蛛池模板: 原阳县| 辰溪县| 稻城县| 历史| 黄冈市| 霍林郭勒市| 香河县| 南和县| 静海县| 大洼县| 洛川县| 乐亭县| 肃南| 怀集县| 东港市| 津市市| 余姚市| 晋中市| 龙游县| 乐至县| 衢州市| 富顺县| 宁波市| 永昌县| 镇原县| 织金县| 博客| 德令哈市| 新巴尔虎左旗| 察隅县| 彰化县| 新绛县| 湘乡市| 余江县| 南平市| 临武县| 栾川县| 芜湖市| 武邑县| 南平市| 连平县|