blob: fed01ed8b1f86a78f4fc4b65d50edb32e0b9c945 [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 Rossumfd71b9e2000-06-30 23:50:40 +00008Copyright (c) 2000, BeOpen.com.
9Copyright (c) 1995-2000, Corporation for National Research Initiatives.
10Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
11All rights reserved.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000012
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013See the file "Misc/COPYRIGHT" for information on usage and
14redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000015******************************************************************/
16
Guido van Rossum3d095431992-01-19 16:30:12 +000017/* This is published for the benefit of "friend" marshal.c only. */
18
Guido van Rossumedcc38a1991-05-05 20:09:44 +000019/* Parameters of the long integer representation.
20 These shouldn't have to be changed as C should guarantee that a short
Tim Peters7d3a5112000-07-08 04:17:21 +000021 contains at least 16 bits, but it's made changeable anyway.
Guido van Rossumedcc38a1991-05-05 20:09:44 +000022 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
29typedef unsigned short digit;
Guido van Rossumbadb1161991-05-14 12:06:16 +000030typedef unsigned int wdigit; /* digit widened to parameter size */
Tim Peters7d3a5112000-07-08 04:17:21 +000031#define BASE_TWODIGITS_TYPE long
32typedef unsigned BASE_TWODIGITS_TYPE twodigits;
33typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
Guido van Rossumedcc38a1991-05-05 20:09:44 +000034
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 Rossum3d095431992-01-19 16:30:12 +000050struct _longobject {
Guido van Rossumcaa63801995-01-12 11:45:45 +000051 PyObject_HEAD
Guido van Rossumb7d3d4e1995-02-10 16:55:33 +000052 int ob_size;
Guido van Rossumedcc38a1991-05-05 20:09:44 +000053 digit ob_digit[1];
Guido van Rossum3d095431992-01-19 16:30:12 +000054};
Guido van Rossumedcc38a1991-05-05 20:09:44 +000055
Tim Peters9f688bf2000-07-07 15:53:28 +000056DL_IMPORT(PyLongObject *) _PyLong_New(int);
Guido van Rossuma3309961993-07-28 09:05:47 +000057
58#ifdef __cplusplus
59}
60#endif
61#endif /* !Py_LONGINTREPR_H */