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

  • Perl 6 Deep Dive
  • Andrew Shitov
  • 100字
  • 2021-07-03 00:05:54

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
主站蜘蛛池模板: 临洮县| 通辽市| 阿克陶县| 武汉市| 仁布县| 景洪市| 枣庄市| 天台县| 东乌珠穆沁旗| 监利县| 友谊县| 米泉市| 明水县| 双桥区| 香河县| 灌南县| 泊头市| 视频| 濮阳市| 天柱县| 舞钢市| 大足县| 赤壁市| 合阳县| 潢川县| 孟津县| 江孜县| 清河县| 梓潼县| 四子王旗| 开鲁县| 祁阳县| 阿巴嘎旗| 陇川县| 大荔县| 乌兰察布市| 辽宁省| 岳西县| 贵阳市| 棋牌| 海宁市|