- 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
推薦閱讀
- Java程序設計與開發
- 自己動手寫搜索引擎
- Mastering Swift 2
- 青少年Python編程入門
- Swift細致入門與最佳實踐
- OpenCV with Python By Example
- HTML+CSS+JavaScript編程入門指南(全2冊)
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- Kotlin極簡教程
- 奔跑吧 Linux內核
- Learning Grunt
- 讓Python遇上Office:從編程入門到自動化辦公實踐
- Learning Zimbra Server Essentials
- JavaScript程序設計基礎教程(慕課版)
- Image Processing with ImageJ(Second Edition)