% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\SingleIntegerXmpTitle}{SingleInteger}
\newcommand{\SingleIntegerXmpNumber}{9.76}
%
% =====================================================================
\begin{page}{SingleIntegerXmpPage}{9.76 SingleInteger}
% =====================================================================
\beginscroll

%
%
%
%
%



%%
%% SINT.htex
%%
%%
The \spadtype{SingleInteger} domain is intended to provide support
%-% \HDindex{integer!machine}{SingleIntegerXmpPage}{9.76}{SingleInteger}
in \Language{} for machine integer arithmetic.
It is generally much faster than (bignum) \spadtype{Integer} arithmetic
but suffers from a limited range of values.
Since \Language{} 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.

The underlying Lisp primitives treat machine-word sized computations
specially.

%Under \spadgloss{AKCL} on the IBM Risc System/6000,
%small integers are restricted
%to the range \spad{-2^26} to
%\spad{2^26 - 1},
%allowing 1 bit for overflow detection.

\xtc{
You can discover the minimum and maximum values in your implementation
by using \spadfunFrom{min}{SingleInteger} and \spadfunFrom{max}{SingleInteger}.
}{
\spadpaste{min()\$SingleInteger}
}
\xtc{
}{
\spadpaste{max()\$SingleInteger}
}
\xtc{
To avoid confusion with \spadtype{Integer}, which is the default
type for integers, you usually need to work with declared variables
(\downlink{``\ugTypesDeclareTitle''}{ugTypesDeclarePage} in Section \ugTypesDeclareNumber\ignore{ugTypesDeclare}) \ldots
}{
\spadpaste{a := 1234 :: SingleInteger \bound{a}}
}
\xtc{
or use package calling
(\downlink{``\ugTypesPkgCallTitle''}{ugTypesPkgCallPage} in Section \ugTypesPkgCallNumber\ignore{ugTypesPkgCall}).
}{
\spadpaste{b := 124\$SingleInteger \bound{b}}
}
\xtc{
You can add, multiply and subtract \spadtype{SingleInteger} objects,
and ask for the greatest common divisor (\spadfun{gcd}).
}{
\spadpaste{gcd(a,b) \free{a}\free{b}}
}
\xtc{
The least common multiple (\spadfun{lcm}) is also available.
}{
\spadpaste{lcm(a,b) \free{a}\free{b}}
}

\xtc{
Operations \spadfunFrom{mulmod}{SingleInteger},
\spadfunFrom{addmod}{SingleInteger},
\spadfunFrom{submod}{SingleInteger}, and
\spadfunFrom{invmod}{SingleInteger} are similar---they provide
arithmetic modulo a given small integer.
Here is \spad{5 * 6 mod 13}.
}{
\spadpaste{mulmod(5,6,13)\$SingleInteger}
}
\xtc{
To reduce a small integer modulo a prime, use \spadfunFrom{positiveRemainder}{SingleInteger}.
}{
\spadpaste{positiveRemainder(37,13)\$SingleInteger}
}
\xtc{
Operations
\spadfunFrom{And}{SingleInteger},
\spadfunFrom{Or}{SingleInteger},
\spadfunFrom{xor}{SingleInteger},
and \spadfunFrom{Not}{SingleInteger}
provide bit level operations on small integers.
}{
\spadpaste{And(3,4)\$SingleInteger}
}
\xtc{
Use
\spad{shift(int,numToShift)} to shift bits, where
\spad{i} is shifted left if \spad{numToShift} is positive, right
if negative.
}{
\spadpaste{shift(1,4)\$SingleInteger}
}
\xtc{
}{
\spadpaste{shift(31,-1)\$SingleInteger}
}

Many other operations are available for small integers, including
many of those provided for \spadtype{Integer}.
To see the other operations, use the Browse \HyperName{} facility
(\downlink{``\ugBrowseTitle''}{ugBrowsePage} in Section \ugBrowseNumber\ignore{ugBrowse}).
\showBlurb{SingleInteger}.
\endscroll
\autobuttons
\end{page}
%
