Merged release21-maint changes.
[python/dscho.git] / Include / longintrepr.h
blob1154e0b02bd537d4dc6e74779a863736423ba72c
1 #ifndef Py_LONGINTREPR_H
2 #define Py_LONGINTREPR_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
8 /* This is published for the benefit of "friend" marshal.c only. */
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 MASK << SHIFT).
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. */
20 typedef unsigned short digit;
21 typedef unsigned int wdigit; /* digit widened to parameter size */
22 #define BASE_TWODIGITS_TYPE long
23 typedef unsigned BASE_TWODIGITS_TYPE twodigits;
24 typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
26 #define SHIFT 15
27 #define BASE ((digit)1 << SHIFT)
28 #define MASK ((int)(BASE - 1))
30 /* Long integer representation.
31 The absolute value of a number is equal to
32 SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
33 Negative numbers are represented with ob_size < 0;
34 zero is represented by ob_size == 0.
35 In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
36 digit) is never zero. Also, in all cases, for all valid i,
37 0 <= ob_digit[i] <= MASK.
38 The allocation function takes care of allocating extra memory
39 so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. */
41 struct _longobject {
42 PyObject_HEAD
43 int ob_size;
44 digit ob_digit[1];
47 DL_IMPORT(PyLongObject *) _PyLong_New(int);
49 #ifdef __cplusplus
51 #endif
52 #endif /* !Py_LONGINTREPR_H */