Literals & quoting

Number forms — Num & Complex

Full

Floating 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
Num

Complex 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.23606797749979

Arithmetic follows the usual complex rules:

say (1+1i) * (1-1i);
Output
2+0i

Notes #