Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_LONGINTREPR_H |
| 2 | #define Py_LONGINTREPR_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 7 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 8 | Copyright (c) 2000, BeOpen.com. |
| 9 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 10 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 11 | All rights reserved. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 13 | See the file "Misc/COPYRIGHT" for information on usage and |
| 14 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 15 | ******************************************************************/ |
| 16 | |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 17 | /* This is published for the benefit of "friend" marshal.c only. */ |
| 18 | |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 19 | /* Parameters of the long integer representation. |
| 20 | These shouldn't have to be changed as C should guarantee that a short |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame^] | 21 | contains at least 16 bits, but it's made changeable anyway. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 22 | Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits' |
| 23 | should be able to hold the intermediate results in 'mul' |
| 24 | (at most MASK << SHIFT). |
| 25 | Also, x_sub assumes that 'digit' is an unsigned type, and overflow |
| 26 | is handled by taking the result mod 2**N for some N > SHIFT. |
| 27 | And, at some places it is assumed that MASK fits in an int, as well. */ |
| 28 | |
| 29 | typedef unsigned short digit; |
Guido van Rossum | badb116 | 1991-05-14 12:06:16 +0000 | [diff] [blame] | 30 | typedef unsigned int wdigit; /* digit widened to parameter size */ |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame^] | 31 | #define BASE_TWODIGITS_TYPE long |
| 32 | typedef unsigned BASE_TWODIGITS_TYPE twodigits; |
| 33 | typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */ |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 34 | |
| 35 | #define SHIFT 15 |
| 36 | #define BASE ((digit)1 << SHIFT) |
| 37 | #define MASK ((int)(BASE - 1)) |
| 38 | |
| 39 | /* Long integer representation. |
| 40 | The absolute value of a number is equal to |
| 41 | SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i) |
| 42 | Negative numbers are represented with ob_size < 0; |
| 43 | zero is represented by ob_size == 0. |
| 44 | In a normalized number, ob_digit[abs(ob_size)-1] (the most significant |
| 45 | digit) is never zero. Also, in all cases, for all valid i, |
| 46 | 0 <= ob_digit[i] <= MASK. |
| 47 | The allocation fuction takes care of allocating extra memory |
| 48 | so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. */ |
| 49 | |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 50 | struct _longobject { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 51 | PyObject_HEAD |
Guido van Rossum | b7d3d4e | 1995-02-10 16:55:33 +0000 | [diff] [blame] | 52 | int ob_size; |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 53 | digit ob_digit[1]; |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 54 | }; |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 55 | |
Tim Peters | 9f688bf | 2000-07-07 15:53:28 +0000 | [diff] [blame] | 56 | DL_IMPORT(PyLongObject *) _PyLong_New(int); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 57 | |
| 58 | #ifdef __cplusplus |
| 59 | } |
| 60 | #endif |
| 61 | #endif /* !Py_LONGINTREPR_H */ |