class Int
Error ReportCollection examples

Integer (arbitrary-precision)

`Int` objects store integral numbers of arbitrary size. `Int`s are immutable.

There are two main syntax forms for `Int` literals

All forms allow underscores between any two digits which can serve as visual separators, but don't carry any meaning:

Radix notation also supports round and angle brackets which allow you to parse a string for a given base, and putting together digits into a whole number respectively:

These notations allow you to use variables, too:

# Methods

method new

Defined as:

The first form will throw an exception; the second and third form will create an new Int from the actual integer value contained in the variable.

## method Capture

Defined as:

Throws `X::Cannot::Capture`.

## routine chr

Defined as:

Returns a one-character string, by interpreting the integer as a Unicode codepoint number and converting it to the corresponding character.

Example:

## routine expmod

Defined as:

Returns the given `Int` raised to the `\$y` power within modulus `\$mod`, that is gives the result of `(\$x ** \$y) mod \$mod`. The subroutine form can accept non-`Int` arguments, which will be coerced to `Int`.

`\$y` argument can also be negative, in which case, the result is equivalent to `(\$x ** \$y)` mod \$mod.

## method polymod

Defined as:

Returns a sequence of mod results corresponding to the divisors in `@mods` in the same order as they appear there. For the best effect, the divisors should be given from the smallest "unit" to the largest (e.g. 60 seconds per minute, 60 minutes per hour) and the results are returned in the same way: from smallest to the largest (5 seconds, 4 minutes). The last non-zero value will be the last remainder.

In the first case, 120 is divided by 10 giving as a remainder 12, which is the last element. In the second, 120 is `div`ided by 10, giving 12, whose remainder once divided by 10 is 2; the result of the integer division of 12 `div` 10 is the last remainder. The number of remainders will be always one more item than the number of given divisors. If the divisors are given as a lazy list, runs until the remainder is 0 or the list of divisors is exhausted. All divisors must be `Int`s, unless the method is called on a non-`Int` number.

To illustrate how the `Int`, non-lazy version of polymod works, consider this code that implements it:

For a more detailed discussion, see this blog post.

We can use lazy lists in `polymod`, as long as they are finite:

## routine is-prime

Defined as:

Returns `True` if this `Int` is known to be a prime, or is likely to be a prime based on a probabilistic Miller-Rabin test.

Returns `False` if this `Int` is known not to be a prime.

## routine lsb

Defined as:

Short for "Least Significant Bit". Returns Nil if the number is 0. Otherwise returns the zero-based index from the right of the least significant (rightmost) 1 in the binary representation of the number.

## routine msb

Defined as:

Short for "Most Significant Bit". Returns Nil if the number is 0. Otherwise returns the zero-based index from the right of the most significant (leftmost) 1 in the binary representation of the number.

## routine unival

Defined as:

Returns the number represented by the Unicode codepoint with the given integer number, or NaN if it does not represent a number.

## method Range

Returns a Range object that represents the range of values supported.

## method Bridge

Defined as:

Returns the integer converted to `Num`.

# Operators

## infix div

Does an integer division, rounded down.