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 | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 8 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 | The Netherlands. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 10 | |
| 11 | All Rights Reserved |
| 12 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 13 | Permission to use, copy, modify, and distribute this software and its |
| 14 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 15 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 16 | both that copyright notice and this permission notice appear in |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 17 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 18 | Centrum or CWI or Corporation for National Research Initiatives or |
| 19 | CNRI not be used in advertising or publicity pertaining to |
| 20 | distribution of the software without specific, written prior |
| 21 | permission. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 23 | While CWI is the initial source for this software, a modified version |
| 24 | is made available by the Corporation for National Research Initiatives |
| 25 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 26 | |
| 27 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 28 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 29 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 30 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 31 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 32 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 33 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 34 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 35 | |
| 36 | ******************************************************************/ |
| 37 | |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 38 | /* This is published for the benefit of "friend" marshal.c only. */ |
| 39 | |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 40 | /* Parameters of the long integer representation. |
| 41 | These shouldn't have to be changed as C should guarantee that a short |
| 42 | contains at least 16 bits, but it's made changeable any way. |
| 43 | Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits' |
| 44 | should be able to hold the intermediate results in 'mul' |
| 45 | (at most MASK << SHIFT). |
| 46 | Also, x_sub assumes that 'digit' is an unsigned type, and overflow |
| 47 | is handled by taking the result mod 2**N for some N > SHIFT. |
| 48 | And, at some places it is assumed that MASK fits in an int, as well. */ |
| 49 | |
| 50 | typedef unsigned short digit; |
Guido van Rossum | badb116 | 1991-05-14 12:06:16 +0000 | [diff] [blame] | 51 | typedef unsigned int wdigit; /* digit widened to parameter size */ |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 52 | typedef unsigned long twodigits; |
Guido van Rossum | badb116 | 1991-05-14 12:06:16 +0000 | [diff] [blame] | 53 | typedef long stwodigits; /* signed variant of twodigits */ |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 54 | |
| 55 | #define SHIFT 15 |
| 56 | #define BASE ((digit)1 << SHIFT) |
| 57 | #define MASK ((int)(BASE - 1)) |
| 58 | |
| 59 | /* Long integer representation. |
| 60 | The absolute value of a number is equal to |
| 61 | SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i) |
| 62 | Negative numbers are represented with ob_size < 0; |
| 63 | zero is represented by ob_size == 0. |
| 64 | In a normalized number, ob_digit[abs(ob_size)-1] (the most significant |
| 65 | digit) is never zero. Also, in all cases, for all valid i, |
| 66 | 0 <= ob_digit[i] <= MASK. |
| 67 | The allocation fuction takes care of allocating extra memory |
| 68 | so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. */ |
| 69 | |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 70 | struct _longobject { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 71 | PyObject_HEAD |
Guido van Rossum | b7d3d4e | 1995-02-10 16:55:33 +0000 | [diff] [blame] | 72 | int ob_size; |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 73 | digit ob_digit[1]; |
Guido van Rossum | 3d09543 | 1992-01-19 16:30:12 +0000 | [diff] [blame] | 74 | }; |
Guido van Rossum | edcc38a | 1991-05-05 20:09:44 +0000 | [diff] [blame] | 75 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 76 | PyLongObject *_PyLong_New Py_PROTO((int)); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 77 | |
| 78 | #ifdef __cplusplus |
| 79 | } |
| 80 | #endif |
| 81 | #endif /* !Py_LONGINTREPR_H */ |