Literals & quoting
Number forms — Num & Complex
FullFloating point via scientific notation, and complex numbers with the i postfix.
Beyond exact Int and Rat, Raku has Num (IEEE 754 floating point) and Complex. Scientific notation produces a Num; the i postfix produces a Complex.
Scientific notation is a Num #
A number written with an e exponent is a Num — floating point, not a rational.
say 1e3; say 1.5e-2; say (1e0).^name;
Output
1000
0.015
NumComplex numbers #
Append i for the imaginary unit. Complex literals print in a+bi form, and .abs gives the magnitude.
say 2i; say (1 + 2i); say (1+2i).abs;
Output
0+2i
1+2i
2.23606797749979Arithmetic follows the usual complex rules:
say (1+1i) * (1-1i);
Output
2+0iNotes #
1e0is the idiomatic way to write "the floating-point one" and to force a value intoNumcontext.Numis inexact — preferRat(a plain decimal like0.1) when you need exact arithmetic; see Rational literals.- The numeric tower is
Int⊂Rat⊂Num⊂Complex; operations promote to the widest type involved.