Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / integer.h
Views: 415069
1
/****************************************************************************
2
**
3
*W integer.h GAP source Martin Schönert
4
** & Alice Niemeyer
5
** & Werner Nickel
6
**
7
**
8
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
9
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
10
*Y Copyright (C) 2002 The GAP Group
11
**
12
** This file declares the functions handling arbitrary size integers.
13
*/
14
15
#ifndef GAP_INTEGER_H
16
#define GAP_INTEGER_H
17
18
#ifdef USE_GMP /* then use the gmp version of the header file */
19
#include "gmpints.h"
20
#else /* read the rest of this file */
21
22
23
/****************************************************************************
24
**
25
26
*T TypDigit . . . . . . . . . . . . . . . . . . . . type of a single digit
27
**
28
** 'TypDigit' is the type of a single digit of an arbitrary size integer.
29
** This is of course unsigned short int, which gives us the 16 bits we want.
30
*/
31
#ifdef SYS_IS_64_BIT
32
typedef UInt4 TypDigit;
33
#define INTEGER_UNIT_SIZE 4
34
#define INTEGER_ALLOCATION_SIZE 16
35
#else
36
typedef UInt2 TypDigit;
37
#define INTEGER_UNIT_SIZE 2
38
#define INTEGER_ALLOCATION_SIZE 8
39
#endif
40
41
#define NR_DIGIT_BITS (8 * sizeof(TypDigit))
42
#define INTBASE (1UL << NR_DIGIT_BITS)
43
#define NR_SMALL_INT_BITS (2*NR_DIGIT_BITS - 4)
44
#define SIZE_INT(op) (SIZE_OBJ(op) / sizeof(TypDigit))
45
#define ADDR_INT(op) ((TypDigit*)ADDR_OBJ(op))
46
47
48
/**************************************************************************
49
** The following two functions convert a C Int or UInt respectively into
50
** a GAP integer, either an immediate, small integer if possible or
51
** otherwise a new GAP bag with TNUM T_INTPOS or T_INTNEG.
52
**
53
*F ObjInt_Int(Int i)
54
*F ObjInt_UInt(UInt i)
55
**
56
****************************************************************************/
57
58
Obj ObjInt_Int(Int i);
59
Obj ObjInt_UInt(UInt i);
60
61
62
/****************************************************************************
63
**
64
*F PrintInt( <int> ) . . . . . . . . . . . . . . . print an integer constant
65
**
66
** 'PrintInt' prints the integer <int> in the usual decimal notation.
67
** 'PrintInt' handles objects of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.
68
*/
69
extern void PrintInt (
70
Obj op );
71
72
73
/****************************************************************************
74
**
75
*F EqInt( <intL>, <intR> ) . . . . . . . . . test if two integers are equal
76
**
77
** 'EqInt' returns 1 if the two integer arguments <intL> and <intR> are
78
** equal and 0 otherwise.
79
*/
80
extern Int EqInt (
81
Obj opL,
82
Obj opR );
83
84
85
/****************************************************************************
86
**
87
*F LtInt( <intL>, <intR> ) . . . . . test if an integer is less than another
88
**
89
** 'LtInt' returns 1 if the integer <intL> is strictly less than the integer
90
** <intR> and 0 otherwise.
91
*/
92
extern Int LtInt (
93
Obj opL,
94
Obj opR );
95
96
97
/****************************************************************************
98
**
99
*F SumInt( <intL>, <intR> ) . . . . . . . . . . . . . . sum of two integers
100
**
101
** 'SumInt' returns the sum of the two integer arguments <intL> and <intR>.
102
** 'SumInt' handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.
103
**
104
** It can also be used in the cases that both operands are small integers
105
** and the result is a small integer too, i.e., that no overflow occurs.
106
** This case is usually already handled in 'EvalSum' for a better efficiency.
107
*/
108
extern Obj SumInt (
109
Obj opL,
110
Obj opR );
111
112
113
/****************************************************************************
114
**
115
*F DiffInt( <intL>, <intR> ) . . . . . . . . . . difference of two integers
116
**
117
** 'DiffInt' returns the difference of the two integer arguments <intL> and
118
** <intR>. 'DiffInt' handles operands of type 'T_INT', 'T_INTPOS' and
119
** 'T_INTNEG'.
120
**
121
** It can also be used in the cases that both operands are small integers
122
** and the result is a small integer too, i.e., that no overflow occurs.
123
** This case is usually already handled in 'EvalDiff' for a better efficiency.
124
*/
125
extern Obj DiffInt (
126
Obj opL,
127
Obj opR );
128
129
130
/****************************************************************************
131
**
132
*F ProdInt( <intL>, <intR> ) . . . . . . . . . . . . product of two integers
133
**
134
** 'ProdInt' returns the product of the two integer arguments <intL> and
135
** <intR>. 'ProdInt' handles operands of type 'T_INT', 'T_INTPOS' and
136
** 'T_INTNEG'.
137
**
138
** It can also be used in the cases that both operands are small integers
139
** and the result is a small integer too, i.e., that no overflow occurs.
140
** This case is usually already handled in 'EvalProd' for a better efficiency.
141
*/
142
extern Obj ProdInt (
143
Obj opL,
144
Obj opR );
145
146
147
/****************************************************************************
148
**
149
*F ModInt( <intL>, <intR> ) . . representant of residue class of an integer
150
**
151
** 'ModInt' returns the smallest positive representant of the residue class
152
** of the integer <intL> modulo the integer <intR>. 'ModInt' handles
153
** operands of type 'T_INT', 'T_INTPOS', 'T_INTNEG'.
154
**
155
** It can also be used in the cases that both operands are small integers
156
** and the result is a small integer too, i.e., that no overflow occurs.
157
** This case is usually already handled in 'EvalMod' for a better efficiency.
158
*/
159
extern Obj ModInt (
160
Obj opL,
161
Obj opR );
162
163
164
/****************************************************************************
165
**
166
*F PowInt( <intL>, <intR> ) . . . . . . . . . . . . . . power of an integer
167
**
168
** 'PowInt' returns the <intR>-th (an integer) power of the integer <intL>.
169
** 'PowInt' is handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.
170
**
171
** It can also be used in the cases that both operands are small integers
172
** and the result is a small integer too, i.e., that no overflow occurs.
173
** This case is usually already handled in 'EvalPow' for a better efficiency.
174
*/
175
extern Obj PowInt (
176
Obj opL,
177
Obj opR );
178
179
180
/****************************************************************************
181
**
182
*F QuoInt( <intL>, <intR> ) . . . . . . . . . . . quotient of two integers
183
**
184
** 'QuoInt' returns the integer part of the two integers <intL> and <intR>.
185
** 'QuoInt' handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.
186
**
187
** It can also be used in the cases that both operands are small integers
188
** and the result is a small integer too, i.e., that no overflow occurs.
189
**
190
** Note that this routine is not called from 'EvalQuo', the division of two
191
** integers yields a rational and is therefor performed in 'QuoRat'.
192
** This operation is however available through the internal function 'Quo'.
193
*/
194
extern Obj QuoInt (
195
Obj opL,
196
Obj opR );
197
198
199
/****************************************************************************
200
**
201
*F RemInt( <intL>, <intR> ) . . . . . . . . . . . remainder of two integers
202
**
203
** 'RemInt' returns the remainder of the quotient of the integers <intL>
204
** and <intR>. 'RemInt' handles operands of type 'T_INT', 'T_INTPOS' and
205
** 'T_INTNEG'.
206
**
207
** Note that the remainder is different from the value returned by the 'mod'
208
** operator which is always positive.
209
*/
210
extern Obj RemInt (
211
Obj opL,
212
Obj opR );
213
214
215
/****************************************************************************
216
**
217
*F GcdInt( <opL>, <opR> ) . . . . . . . . . . . . . . . gcd of two integers
218
**
219
** 'GcdInt' returns the gcd of the two integers <opL> and <opR>.
220
*/
221
extern Obj GcdInt (
222
Obj opL,
223
Obj opR );
224
225
226
extern Int CLog2Int(Int a);
227
extern Obj FuncLog2Int( Obj self, Obj intnum);
228
229
/****************************************************************************
230
**
231
232
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
233
*/
234
235
/****************************************************************************
236
** \
237
\
238
239
*F InitInfoInt() . . . . . . . . . . . . . . . . . . table of init functions
240
*/
241
StructInitInfo * InitInfoInt ( void );
242
243
244
#endif // USE_GMP
245
246
#endif // GAP_INTEGER_H
247
248
/****************************************************************************
249
**
250
*E integer.c . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
251
*/
252
253