Instances of the INTEGER signature provide a type of signed integers
of either a fixed or arbitrary precision, and arithmetic and
conversion operations. For fixed precision implementations, most
arithmetic operations raise the exception Overflow when their result
is not representable.
returns the int representation of the LargeInt.int value
i. Raises Overflow if the value does not fit. Int<M>.fromLarge o
Int<N>.toLarge converts an integer from type Int<N>.int to Int<M>.int.
If SOME(n), this denotes the number n of significant bits
in type int, including the sign bit. If it is NONE, int has arbitrary
precision. The precision need not necessarily be a power of two.
is the minimal (most negative) integer, representable by
int. If NONE, int can represent all negative integers, within the
limits of the heap size. If precision is SOME(n), then we have minInt
= -2(n-1).
is the maximal (most positive) integer, representable by
int. If NONE, int can represent all positive integers, within the
limits of the heap size. If precision is SOME(n), then we have maxInt
= 2(n-1) - 1.
returns the greatest integer less than or equal to the
quotient of i by j, i.e., floor(((i / j))). It raises Overflow when
the result is not representable, or Div when j = 0. Note that rounding
is towards negative infinity, not zero.
returns the truncated quotient of the division of i by
j, i.e., it computes (i / j) and then drops any fractional part of the
quotient. It raises Overflow when the result is not representable, or
Div when j = 0. Note that unlike div, quot rounds towards zero. In
addition, unlike div and mod, neither quot nor rem are infix by
default; an appropriate infix declaration would be infix 7 quot rem.
This is the semantics of most hardware divide instructions, so quot
may be faster than div.
returns the negation of i, i.e., (0 - i). It raises Overflow
when the result is not representable. This can happen, for example,
when int is an n-bit 2's-complement integer type, and ~ is applied to
-2 (n-1).
returns a string containing a representation of i with
#"~" used as the sign for negative numbers. The string is formatted
according to radix. The hexadecimal digits 10 through 15 are
represented as #"A" through #"F", respectively. No prefix "0x" is
generated for the hexadecimal representation.
returns SOME(i,rest) if an integer in the
format denoted by radix can be parsed from a prefix of the character
stream strm after skipping initial whitespace, where i is the value of
the integer parsed and rest is the rest of the character stream. NONE
is returned otherwise. Raises Overflow when an integer can be parsed,
but is too large to be represented by type int.
The format that scan accepts depends on the radix argument. Regular
expressions defining these formats are as follows:
Radix Format
StringCvt.BIN [+~-]?[0-1]+
StringCvt.OCT [+~-]?[0-7]+
StringCvt.DEC [+~-]?[0-9]+
Note that strings such as "0xg" and "0x 123" are scanned as SOME(0),
even using a hexadecimal radix.
?[0-9]+ can be parsed from a prefix of the string s, ignoring
initial whitespace; NONE is returned otherwise. Raises Overflow when
an integer can be parsed, but is too large to fit in type int. It is
equivalent to the expression StringCvt.scanString (scan
StringCvt.DEC).