Instances of the Int class are integers. Each integer object is either negative, zero or positive. Their range is essentially unlimited: they can represent both very large and very small integers with thousands of digits.
Integer literals and arithmetic operations are the most common ways of constructing integer objects. Besides arithmetic, integers are also used for indexing strings and arrays. @class Int(x[, base as Int]) @desc Construct an object of the Int type. Call the _int() method of the first argument and return a value equal to the result, provided that it is an integer. Of the primitive types, Str and Float objects provide an _int method. Float arguments are converted to integers by truncating any fractions. String arguments may contain optional blank and tab characters before and after the number, and the number must be in base 10 (decimal) by default.
The base argument is only valid for conversions from strings. It specifies the base of the string, overriding the default base 10. Valid values are from 2 to 36, inclusive. Digit values greater than 9 are represented as letters from "a" to "z", such that "a" or "A" is 10, "b" or "B" is 11, etc. @see @ref{string::IntToStr} can be used to convert integers to strings in different bases. @end @end @see @ref{Float} objects also define operations that accept integer operands. For example, 1.5 + 2 evaluates to 3.5, as expected. @end
Int objects support the following operations (n below
refers to an Int value):
@op n + x @optype{Int + Int -> Int; Int + Float -> Float}
@desc Perform an addition operation. If x is an
integer,
the result is also an integer, and if x is a float,
the result is a float.
@end
@op n + x @optype{Int + Addable
@end
@op -n @optype{-Int -> Int}
@desc Return the negation of an integer.
@end
@op n == x @optype{Int == Object -> Boolean}
@desc Integers can be compared for equality with arbitrary objects.
An integer object is equal to an equivalent integer or float value.
If x is neither an integer nor a float,
the operation is evaluated as x == n instead.
@note The last property enables user-defined types to be compared with
integers usefully.
@end
@end
@op n < x @optype{Int < Int -> Boolean; Int < Float -> Boolean}
@op n > x @optype{Int > Int -> Boolean; Int > Float -> Boolean}
@desc Integers can be compared for order with integers and floats.
If x is neither an integer nor a float,
the operation is evaluated as x > n
(for a < operation) or x < n (for a > operation).
@note The last property allows user-defined types to be compared with
integers usefully.
@end
@end
@op Str(n)
@desc Convert an integer to a string in base 10 (decimal).
@end
@op Float(n)
@desc Convert an integer to a float.
@end
@op Hash(n)
@desc Return the hash value of an integer.
@end