📘 Int type in Perl 6

The Int type is intended to host integer variables of arbitrary size. For example, no digit is lost in the following assignment:

my Int $x =
    12389147319583948275874801735817503285431532;
say $x;

A special syntax exists for defining integers with an other-than-10 base:

say :16<D0CF11E0>

Also, it is allowable to use the underscore character to separate digits so that big numbers can be read more easily:

my Int $x = 735_817_503_285_431_532;

Of course, when you print the value, all the underscores are gone.

On the Int object, you may call some other handy methods, for example, to convert a number to a character or to check if the integer in hand is prime (yes, is-prime is a built-in method!).

my Int $a = 65;
say $a.chr; # A

my Int $i = 17;
say $i.is-prime; # True

say 42.is-prime; # False

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s