aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/SINT.ht
blob: fdadf644c4a763f6eaa195b1867705f128c25a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\SingleIntegerXmpTitle}{SingleInteger}
\newcommand{\SingleIntegerXmpNumber}{9.72}
%
% =====================================================================
\begin{page}{SingleIntegerXmpPage}{9.72 SingleInteger}
% =====================================================================
\beginscroll

%%
%% SINT.htex
%%
%%
The \axiomType{SingleInteger} domain is intended to provide support
%-% \HDindex{integer!machine}{SingleIntegerXmpPage}{9.72}{SingleInteger}
in \Language{} for machine integer arithmetic.
It is generally much faster than (bignum) \axiomType{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.

In the CCL implementation of AXIOM (Release 2.1 onwards) the underlying
representation of \axiomType{SingleInteger} is the same as \axiomType{Integer}.  
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 \texht{$-{2^{26}}$}{\spad{-2**26}} to
%\texht{${2^{26}}-1$}{\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 \axiomType{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 \axiomType{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 {\tt 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 \axiomType{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}
%