blob: 84f352401480f6a53d8235634e755d79f9ea80af [file] [log] [blame]
Guido van Rossumedcc38a1991-05-05 20:09:44 +00001/***********************************************************
Guido van Rossum5113f5f1992-04-05 14:20:22 +00002Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Guido van Rossumedcc38a1991-05-05 20:09:44 +00003Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum3d095431992-01-19 16:30:12 +000025/* This is published for the benefit of "friend" marshal.c only. */
26
Guido van Rossumedcc38a1991-05-05 20:09:44 +000027/* Parameters of the long integer representation.
28 These shouldn't have to be changed as C should guarantee that a short
29 contains at least 16 bits, but it's made changeable any way.
30 Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
31 should be able to hold the intermediate results in 'mul'
32 (at most MASK << SHIFT).
33 Also, x_sub assumes that 'digit' is an unsigned type, and overflow
34 is handled by taking the result mod 2**N for some N > SHIFT.
35 And, at some places it is assumed that MASK fits in an int, as well. */
36
37typedef unsigned short digit;
Guido van Rossumbadb1161991-05-14 12:06:16 +000038typedef unsigned int wdigit; /* digit widened to parameter size */
Guido van Rossumedcc38a1991-05-05 20:09:44 +000039typedef unsigned long twodigits;
Guido van Rossumbadb1161991-05-14 12:06:16 +000040typedef long stwodigits; /* signed variant of twodigits */
Guido van Rossumedcc38a1991-05-05 20:09:44 +000041
42#define SHIFT 15
43#define BASE ((digit)1 << SHIFT)
44#define MASK ((int)(BASE - 1))
45
46/* Long integer representation.
47 The absolute value of a number is equal to
48 SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
49 Negative numbers are represented with ob_size < 0;
50 zero is represented by ob_size == 0.
51 In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
52 digit) is never zero. Also, in all cases, for all valid i,
53 0 <= ob_digit[i] <= MASK.
54 The allocation fuction takes care of allocating extra memory
55 so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. */
56
Guido van Rossum3d095431992-01-19 16:30:12 +000057struct _longobject {
Guido van Rossumedcc38a1991-05-05 20:09:44 +000058 OB_HEAD
59 int ob_size; /* XXX Hack! newvarobj() stores it as unsigned! */
60 digit ob_digit[1];
Guido van Rossum3d095431992-01-19 16:30:12 +000061};
Guido van Rossumedcc38a1991-05-05 20:09:44 +000062
Guido van Rossumedcc38a1991-05-05 20:09:44 +000063longobject *alloclongobject PROTO((int));