blob: 3630bd7539492759ecb6485373d8cbec6bfba288 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_LONGINTREPR_H
2#define Py_LONGINTREPR_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumedcc38a1991-05-05 20:09:44 +00007/***********************************************************
Guido van Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000010
11 All Rights Reserved
12
Guido van Rossumd266eb41996-10-25 14:44:06 +000013Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
Guido van Rossumedcc38a1991-05-05 20:09:44 +000015provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000016both that copyright notice and this permission notice appear in
Guido van Rossumedcc38a1991-05-05 20:09:44 +000017supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000018Centrum or CWI or Corporation for National Research Initiatives or
19CNRI not be used in advertising or publicity pertaining to
20distribution of the software without specific, written prior
21permission.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000022
Guido van Rossumd266eb41996-10-25 14:44:06 +000023While CWI is the initial source for this software, a modified version
24is made available by the Corporation for National Research Initiatives
25(CNRI) at the Internet address ftp://ftp.python.org.
26
27STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000035
36******************************************************************/
37
Guido van Rossum3d095431992-01-19 16:30:12 +000038/* This is published for the benefit of "friend" marshal.c only. */
39
Guido van Rossumedcc38a1991-05-05 20:09:44 +000040/* 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
50typedef unsigned short digit;
Guido van Rossumbadb1161991-05-14 12:06:16 +000051typedef unsigned int wdigit; /* digit widened to parameter size */
Guido van Rossumedcc38a1991-05-05 20:09:44 +000052typedef unsigned long twodigits;
Guido van Rossumbadb1161991-05-14 12:06:16 +000053typedef long stwodigits; /* signed variant of twodigits */
Guido van Rossumedcc38a1991-05-05 20:09:44 +000054
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 Rossum3d095431992-01-19 16:30:12 +000070struct _longobject {
Guido van Rossumcaa63801995-01-12 11:45:45 +000071 PyObject_HEAD
Guido van Rossumb7d3d4e1995-02-10 16:55:33 +000072 int ob_size;
Guido van Rossumedcc38a1991-05-05 20:09:44 +000073 digit ob_digit[1];
Guido van Rossum3d095431992-01-19 16:30:12 +000074};
Guido van Rossumedcc38a1991-05-05 20:09:44 +000075
Guido van Rossumcaa63801995-01-12 11:45:45 +000076PyLongObject *_PyLong_New Py_PROTO((int));
Guido van Rossuma3309961993-07-28 09:05:47 +000077
78#ifdef __cplusplus
79}
80#endif
81#endif /* !Py_LONGINTREPR_H */