Integer Prototype

The int prototype ($int_proto) defines verbs that perform operations on the receiver, which will be of type INT. All verbs are of the general form:

any int:verb(...)

Where int may be a integer literal or an expression returning a integer value.


INT int:is_even()

Returns true if int is an even integer.

1:is_even()      => 0
2:is_even()      => 1


INT int:is_odd()

Returns true if int is an odd integer.

1:is_odd()       => 1
2:is_odd()       => 0


INT int:gcd(INT other)

Calculates the greatest common divisor of int and other.

54:gcd(24)      => 6
68:gcd(32)      => 4


INT int:lcm(INT other)

Calculates the least common multiple of int and other.

12:lcm(26)      => 156
68:lcm(32)      => 544


INT int:is_prime()

Returns true if int is a prime number.

2203:is_prime()      => 1

tostr to_str

STR int:tostr([INT base])

Returns the string representation of int in the specified base. If base is not specified, it defaults to 10. The base must be between 2 and 16, inclusive.

44:tostr()      => "44"
44:tostr(10)    => "44"
44:tostr(2)     => "101100"
44:tostr(16)    => "2C"


STR index:chr()

Returns the character at index in the MOO subset of the ASCII character set (the printable characters). If index is outside that set, the verb raises E_INVARG.

44:chr()    => ","
94:chr()    => "^"