📘 The number π in Perl 6

📘 The number π in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


Print the value of π.

The value of  is accessible with no additional modules:

say π;

This instruction, not a surprise, prints the desired value:

3.14159265358979

As you may have noticed, a non-ASCII character was used in the code. Perl 6 assumes that the source code is encoded as UTF-8 by default. Instead, a non-Unicode version can be used, too:

say pi;

There are a couple more constants built-in in Perl 6: tau and e; both of them have Unicode variants:  and  (character code 0x1D452):

say τ;
say e;

The value of tau is equal to 2π, and the above program prints the following result:

6.28318530717959
2.71828182845905

It is also worth knowing that in Perl 6, there’s a special constant for presenting infinity: Inf or . This number is bigger than any other (reasonably big) number; either an integer or a floating-point value.

say 1E120 < ∞; # Prints True

Leave a Reply