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 / gmpints.h
Views: 415066
1
/****************************************************************************
2
**
3
*W gmpints.h GAP source John McDermott
4
**
5
**
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 gmp integers.
13
*/
14
15
#ifndef GAP_GMPINTS_H
16
#define GAP_GMPINTS_H
17
18
#ifdef USE_GMP
19
20
// GMP must be included outside of 'extern C'
21
#ifdef GAP_IN_EXTERN_C
22
}
23
#endif
24
#include <gmp.h>
25
#ifdef GAP_IN_EXTERN_C
26
extern "C" {
27
#endif
28
29
/****************************************************************************
30
**
31
*T TypLimb . . . . . . . . . . . . . . . . . . . . . . . type of a GMP Limb
32
**
33
**
34
**
35
*/
36
typedef mp_limb_t TypLimb;
37
typedef mp_size_t TypGMPSize;
38
39
40
// TODO: Instead of hardcoding the values below, use
41
// GMP_LIMB_BITS etc. directly.
42
//
43
// To safeguard against bugs like compiling GAP against one version of
44
// GMP and a plugin against another, we may want to add some safeguards.
45
// E.g. add to config.h another #define GAP_GMP_LIMB_BITS and compare
46
// that during compile time with GMP_LIMB_BITS.
47
48
49
#ifdef SYS_IS_64_BIT
50
#define INTEGER_UNIT_SIZE 8
51
#define INTEGER_ALLOCATION_SIZE 8
52
#define NR_SMALL_INT_BITS (64 - 4)
53
#else
54
#define INTEGER_UNIT_SIZE 4
55
#define INTEGER_ALLOCATION_SIZE 4
56
#define NR_SMALL_INT_BITS (32 - 4)
57
#endif
58
59
#if GMP_LIMB_BITS != INTEGER_UNIT_SIZE * 8
60
#error Aborting compile: unexpected GMP limb size
61
#endif
62
#if GMP_NAIL_BITS != 0
63
#error Aborting compile: GAP does not support non-zero GMP nail size
64
#endif
65
#ifndef __GNU_MP_RELEASE
66
#if __GMP_MP_RELEASE < 50002
67
#error Aborting compile: GAP requires GMP 5.0.2 or newer
68
#endif
69
#endif
70
71
72
#define ADDR_INT(obj) ( (TypLimb *)ADDR_OBJ(obj) )
73
#define SIZE_INT(obj) ( (TypGMPSize)SIZE_OBJ(obj)/sizeof(TypLimb) )
74
/* SIZE_INT gives a result in limbs */
75
76
77
/**************************************************************************
78
** The following two functions convert a C Int or UInt respectively into
79
** a GAP integer, either an immediate, small integer if possible or
80
** otherwise a new GAP bag with TNUM T_INTPOS or T_INTNEG.
81
**
82
*F ObjInt_Int(Int i)
83
*F ObjInt_UInt(UInt i)
84
**
85
****************************************************************************/
86
87
Obj ObjInt_Int(Int i);
88
Obj ObjInt_UInt(UInt i);
89
90
/****************************************************************************
91
**
92
*/
93
extern Obj GMP_REDUCE (
94
Obj gmp );
95
extern Obj GMP_NORMALIZE (
96
Obj gmp );
97
98
99
/****************************************************************************
100
**
101
*F PrintInt( <int> ) . . . . . . . . . . . . . . . print an integer constant
102
**
103
** 'PrintInt' prints the integer <int> in the usual decimal notation.
104
** 'PrintInt' handles objects of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.
105
*/
106
extern void PrintInt (
107
Obj op );
108
109
110
/****************************************************************************
111
**
112
*F EqInt( <gmpL>, <gmpR> ) . . . . . test if two integers are equal
113
**
114
** 'EqInt' returns 1 if the two GMP integer arguments <gmpL> and
115
** <gmpR> are equal and 0 otherwise.
116
*/
117
extern Int EqInt (
118
Obj opL,
119
Obj opR );
120
121
122
/****************************************************************************
123
**
124
*F LtInt( <gmpL>, <gmpR> ) test if an integer is less than another
125
**
126
** 'LtInt' returns 1 if the integer <gmpL> is strictly less than the
127
** integer <gmpR> and 0 otherwise.
128
*/
129
extern Int LtInt (
130
Obj opL,
131
Obj opR );
132
133
134
/****************************************************************************
135
**
136
*F SumInt( <gmpL>, <gmpR> ) . . . . . . . . . sum of two integers
137
**
138
** 'SumInt' returns the sum of the two integer arguments <gmpL> and
139
** <gmpR>.
140
**
141
*/
142
extern Obj SumInt (
143
Obj opL,
144
Obj opR );
145
146
/****************************************************************************
147
**
148
*F SumOrDiffInt( <gmpL>, <gmpR>, <sign> ) . . . . . . . sum of two integers
149
**
150
** 'SumOrDiffInt' returns the sum or difference of the two GMP arguments
151
** <gmpL> and <gmpR>, depending whether sign is +1 or -1.
152
**
153
*/
154
extern Obj SumOrDiffInt (
155
Obj opL,
156
Obj opR,
157
Int sign );
158
159
160
/****************************************************************************
161
**
162
*F DiffInt( <gmpL>, <gmpR> ) . . . . difference of two GMP integers
163
**
164
** 'DiffInt' returns the difference of the two integer arguments <gmpL>
165
** and <gmpR>.
166
**
167
*/
168
extern Obj DiffInt (
169
Obj opL,
170
Obj opR );
171
172
/****************************************************************************
173
**
174
*F ProdInt( <gmpL>, <gmpR> ) . . . . . product of two GMP integers
175
**
176
** 'ProdInt' returns the product of the two integer arguments <gmpL>
177
** and <gmpR>.
178
**
179
*/
180
extern Obj ProdInt (
181
Obj opL,
182
Obj opR );
183
184
185
/****************************************************************************
186
**
187
*F ModInt( <gmpL>, <gmpR> ) representant of res cl of a GMP integer
188
**
189
** 'ModInt' returns the smallest positive representant of the residue
190
** class of the integer <gmpL> modulo the integer <gmpR>.
191
**
192
*/
193
extern Obj ModInt (
194
Obj opL,
195
Obj opR );
196
197
198
/****************************************************************************
199
**
200
*F PowInt( <gmpL>, <gmpR> ) . . . . . . . . power of a GMP integer
201
**
202
** 'PowInt' returns the <gmpR>-th (a GMP int) power of the GMP integer
203
** <gmpL>.
204
**
205
*/
206
extern Obj PowInt (
207
Obj opL,
208
Obj opR );
209
210
211
/****************************************************************************
212
**
213
*F QuoInt( <gmpL>, <gmpR> ) . . . . . quotient of two GMP integers
214
**
215
** 'QuoInt' returns the integer part of the two integers <gmpL> and
216
** <gmpR>.
217
**
218
*/
219
extern Obj QuoInt (
220
Obj opL,
221
Obj opR );
222
223
224
/****************************************************************************
225
**
226
*F RemInt( <gmpL>, <gmpR> ) . . . . remainder of two GMP integers
227
**
228
** 'RemInt' returns the remainder of the quotient of the GMP ints
229
** <gmpL> and <gmpR>.
230
**
231
*/
232
extern Obj RemInt (
233
Obj opL,
234
Obj opR );
235
236
237
/****************************************************************************
238
**
239
*F GcdInt( <gmpL>, <gmpR> ) . . . . . . . gcd of two GMP integers
240
**
241
** 'GcdInt' returns the gcd of the two integers <gmpL> and <gmpR>.
242
*/
243
extern Obj GcdInt (
244
Obj opL,
245
Obj opR );
246
247
248
extern Int CLog2Int(Int intnum);
249
extern Obj FuncLog2Int( Obj self, Obj intnum);
250
251
extern Obj AInvInt ( Obj gmp );
252
253
/****************************************************************************
254
**
255
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
256
*/
257
258
259
/****************************************************************************
260
**
261
*F InitInfoInt() . . . . . . . . . . . . . . . . table of init functions
262
*/
263
StructInitInfo * InitInfoInt ( void );
264
265
#endif // USE_GMP
266
267
#endif // GAP_GMPINTS_H
268
269
/****************************************************************************
270
**
271
*E gmpints.h . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
272
*/
273
274