1 #ifndef Py_LONGINTREPR_H
2 #define Py_LONGINTREPR_H
7 /***********************************************************
8 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
13 Permission to use, copy, modify, and distribute this software and its
14 documentation for any purpose and without fee is hereby granted,
15 provided that the above copyright notice appear in all copies and that
16 both that copyright notice and this permission notice appear in
17 supporting documentation, and that the names of Stichting Mathematisch
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
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.
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.
36 ******************************************************************/
38 /* This is published for the benefit of "friend" marshal.c only. */
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. */
50 typedef unsigned short digit
;
51 typedef unsigned int wdigit
; /* digit widened to parameter size */
52 typedef unsigned long twodigits
;
53 typedef long stwodigits
; /* signed variant of twodigits */
56 #define BASE ((digit)1 << SHIFT)
57 #define MASK ((int)(BASE - 1))
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. */
76 DL_IMPORT(PyLongObject
*) _PyLong_New
Py_PROTO((int));
81 #endif /* !Py_LONGINTREPR_H */