NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX

The Int structure

The Int structure contains many arithmetic operators. Some of these, such as Int.quot and Int.rem, are subtle variants on more familiar operators such as div and mod. Quotient and remainder differ from divisor and modulus in their behaviour with negative operands. Other operations on integers include Int.abs and Int.min and Int.max, which behave as expected. This structure also provides conversions to and from strings, named Int.toString and Int.fromString, of course. An additional formatting function provides the ability to represent integers in bases other than decimal. The chosen base is specified using a type which is defined in another library structure, the string convertors structure, StringCvt. This permits very convenient formatting of integers in binary, octal, decimal or hexadecimal, as shown below.

Int.fmt StringCvt.BIN 1024 = "10000000000"
Int.fmt StringCvt.OCT 1024 = "2000"
Int.fmt StringCvt.DEC 1024 = "1024"
Int.fmt StringCvt.HEX 1024 = "400"

The Int structure may define largest and smallest integer values. This is not to say that structures may arbitrarily shrink or grow in size, Int.maxInt either takes the value NONE or SOME i, with i being an integer value. Int.minInt has the same type.

NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX