]>
Book Contents Previous Section 9.71 Set Next Section 9.73 SparseTable Book Index

## 9.72 SingleInteger

The SingleInteger domain is intended to provide support in Axiom for machine integer arithmetic. It is generally much faster than (bignum) Integer arithmetic but suffers from a limited range of values. Since Axiom can be implemented on top of various dialects of Lisp, the actual representation of small integers may not correspond exactly to the host machines integer representation.

In the CCL implementation of AXIOM (Release 2.1 onwards) the underlying representation of SingleInteger is the same as Integer. The underlying Lisp primitives treat machine-word sized computations specially.

You can discover the minimum and maximum values in your implementation by using min min SingleInteger and max max SingleInteger.

min()$SingleInteger

-134217728

Type: SingleInteger
max()$SingleInteger

134217727

Type: SingleInteger

To avoid confusion with Integer, which is the default type for integers, you usually need to work with declared variables (ugTypesDeclarePage in Section ugTypesDeclareNumber ) ...

a := 1234 :: SingleInteger

1234

Type: SingleInteger

or use package calling (ugTypesPkgCallPage in Section ugTypesPkgCallNumber ).

b := 124$SingleInteger

124

Type: SingleInteger

You can add, multiply and subtract SingleInteger objects, and ask for the greatest common divisor (gcd).

gcd(a,b)

2

Type: SingleInteger

The least common multiple (lcm) is also available.

lcm(a,b)

76508

Type: SingleInteger

Operations mulmod mulmod SingleInteger, addmod addmod SingleInteger, submod submod SingleInteger, and invmod invmod SingleInteger are similar---they provide arithmetic modulo a given small integer. Here is 5*6 mod 13.

mulmod(5,6,13)$SingleInteger

4

Type: SingleInteger

To reduce a small integer modulo a prime, use positiveRemainder positiveRemainder SingleInteger.

positiveRemainder(37,13)$SingleInteger

11

Type: SingleInteger

Operations And And SingleInteger, Or Or SingleInteger, xor xor SingleInteger, and Not Not SingleInteger provide bit level operations on small integers.

And(3,4)$SingleInteger

0

Type: SingleInteger

Use shift(int,numToShift) to shift bits, where i is shifted left if numToShift is positive, right if negative.

shift(1,4)$SingleInteger

16

Type: SingleInteger
shift(31,-1)$SingleInteger

15

Type: SingleInteger

Many other operations are available for small integers, including many of those provided for Integer. To see the other operations, use the Browse HyperDoc facility (ugBrowsePage in Section ugBrowseNumber ).

Book Contents Previous Section 9.71 Set Next Section 9.73 SparseTable Book Index