|
1 #ifndef Py_LONGINTREPR_H |
|
2 #define Py_LONGINTREPR_H |
|
3 #ifdef __cplusplus |
|
4 extern "C" { |
|
5 #endif |
|
6 |
|
7 |
|
8 /* This is published for the benefit of "friend" marshal.c only. */ |
|
9 |
|
10 /* Parameters of the long integer representation. |
|
11 These shouldn't have to be changed as C should guarantee that a short |
|
12 contains at least 16 bits, but it's made changeable anyway. |
|
13 Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits' |
|
14 should be able to hold the intermediate results in 'mul' |
|
15 (at most (BASE-1)*(2*BASE+1) == MASK*(2*MASK+3)). |
|
16 Also, x_sub assumes that 'digit' is an unsigned type, and overflow |
|
17 is handled by taking the result mod 2**N for some N > SHIFT. |
|
18 And, at some places it is assumed that MASK fits in an int, as well. |
|
19 long_pow() requires that SHIFT be divisible by 5. */ |
|
20 |
|
21 typedef unsigned short digit; |
|
22 typedef unsigned int wdigit; /* digit widened to parameter size */ |
|
23 #define BASE_TWODIGITS_TYPE long |
|
24 typedef unsigned BASE_TWODIGITS_TYPE twodigits; |
|
25 typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */ |
|
26 |
|
27 #define PyLong_SHIFT 15 |
|
28 #define PyLong_BASE ((digit)1 << PyLong_SHIFT) |
|
29 #define PyLong_MASK ((int)(PyLong_BASE - 1)) |
|
30 |
|
31 /* b/w compatibility with Python 2.5 */ |
|
32 #define SHIFT PyLong_SHIFT |
|
33 #define BASE PyLong_BASE |
|
34 #define MASK PyLong_MASK |
|
35 |
|
36 #if PyLong_SHIFT % 5 != 0 |
|
37 #error "longobject.c requires that PyLong_SHIFT be divisible by 5" |
|
38 #endif |
|
39 |
|
40 /* Long integer representation. |
|
41 The absolute value of a number is equal to |
|
42 SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i) |
|
43 Negative numbers are represented with ob_size < 0; |
|
44 zero is represented by ob_size == 0. |
|
45 In a normalized number, ob_digit[abs(ob_size)-1] (the most significant |
|
46 digit) is never zero. Also, in all cases, for all valid i, |
|
47 0 <= ob_digit[i] <= MASK. |
|
48 The allocation function takes care of allocating extra memory |
|
49 so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. |
|
50 |
|
51 CAUTION: Generic code manipulating subtypes of PyVarObject has to |
|
52 aware that longs abuse ob_size's sign bit. |
|
53 */ |
|
54 |
|
55 struct _longobject { |
|
56 PyObject_VAR_HEAD |
|
57 digit ob_digit[1]; |
|
58 }; |
|
59 |
|
60 PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t); |
|
61 |
|
62 /* Return a copy of src. */ |
|
63 PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src); |
|
64 |
|
65 #ifdef __cplusplus |
|
66 } |
|
67 #endif |
|
68 #endif /* !Py_LONGINTREPR_H */ |