Mercurial > cpython-lru_cache-weakref
annotate Objects/longobject.c @ 15842:f6cd36498a50 legacy-trunk
Document extensions to .pth files.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 13 Jan 2001 09:54:41 +0000 |
| parents | 8e402aeca0a3 |
| children | 4f621708514b |
| rev | line source |
|---|---|
| 230 | 1 |
| 2 /* Long (arbitrary precision) integer object implementation */ | |
| 3 | |
| 242 | 4 /* XXX The functional organization of this file is terrible */ |
| 5 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
6 #include "Python.h" |
| 230 | 7 #include "longintrepr.h" |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
8 |
| 230 | 9 #include <assert.h> |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
10 #include <ctype.h> |
| 230 | 11 |
| 613 | 12 #define ABS(x) ((x) < 0 ? -(x) : (x)) |
| 13 | |
| 14 /* Forward */ | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
15 static PyLongObject *long_normalize(PyLongObject *); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
16 static PyLongObject *mul1(PyLongObject *, wdigit); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
17 static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
18 static PyLongObject *divrem1(PyLongObject *, wdigit, digit *); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
19 static PyObject *long_format(PyObject *aa, int base, int addL); |
| 613 | 20 |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
21 static int ticker; /* XXX Could be shared with ceval? */ |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
22 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
23 #define SIGCHECK(PyTryBlock) \ |
| 242 | 24 if (--ticker < 0) { \ |
| 25 ticker = 100; \ | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
26 if (PyErr_CheckSignals()) { PyTryBlock; } \ |
| 242 | 27 } |
| 28 | |
| 230 | 29 /* Normalize (remove leading zeros from) a long int object. |
| 30 Doesn't attempt to free the storage--in most cases, due to the nature | |
| 31 of the algorithms used, this could save at most be one word anyway. */ | |
| 32 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
33 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
34 long_normalize(register PyLongObject *v) |
| 230 | 35 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
36 int j = ABS(v->ob_size); |
| 230 | 37 register int i = j; |
| 38 | |
| 39 while (i > 0 && v->ob_digit[i-1] == 0) | |
| 40 --i; | |
| 41 if (i != j) | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
42 v->ob_size = (v->ob_size < 0) ? -(i) : i; |
| 230 | 43 return v; |
| 44 } | |
| 45 | |
| 46 /* Allocate a new long int object with size digits. | |
| 47 Return NULL and set exception if we run out of memory. */ | |
| 48 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
49 PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
50 _PyLong_New(int size) |
| 230 | 51 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
52 return PyObject_NEW_VAR(PyLongObject, &PyLong_Type, size); |
| 230 | 53 } |
| 54 | |
| 55 /* Create a new long int object from a C long int */ | |
| 56 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
57 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
58 PyLong_FromLong(long ival) |
| 230 | 59 { |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
60 /* Assume a C long fits in at most 5 'digits' */ |
|
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
61 /* Works on both 32- and 64-bit machines */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
62 PyLongObject *v = _PyLong_New(5); |
| 230 | 63 if (v != NULL) { |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
64 unsigned long t = ival; |
|
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
65 int i; |
| 230 | 66 if (ival < 0) { |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
67 t = -ival; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
68 v->ob_size = -(v->ob_size); |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
69 } |
|
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
70 for (i = 0; i < 5; i++) { |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
71 v->ob_digit[i] = (digit) (t & MASK); |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
72 t >>= SHIFT; |
| 230 | 73 } |
| 74 v = long_normalize(v); | |
| 75 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
76 return (PyObject *)v; |
| 230 | 77 } |
| 78 | |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
79 /* Create a new long int object from a C unsigned long int */ |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
80 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
81 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
82 PyLong_FromUnsignedLong(unsigned long ival) |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
83 { |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
84 /* Assume a C long fits in at most 5 'digits' */ |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
85 /* Works on both 32- and 64-bit machines */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
86 PyLongObject *v = _PyLong_New(5); |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
87 if (v != NULL) { |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
88 unsigned long t = ival; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
89 int i; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
90 for (i = 0; i < 5; i++) { |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
91 v->ob_digit[i] = (digit) (t & MASK); |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
92 t >>= SHIFT; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
93 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
94 v = long_normalize(v); |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
95 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
96 return (PyObject *)v; |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
97 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
98 |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
99 /* Create a new long int object from a C double */ |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
100 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
101 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
102 PyLong_FromDouble(double dval) |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
103 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
104 PyLongObject *v; |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
105 double frac; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
106 int i, ndig, expo, neg; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
107 neg = 0; |
|
13976
5ada9fa54801
Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
Tim Peters <tim.peters@gmail.com>
parents:
13761
diff
changeset
|
108 if (Py_IS_INFINITY(dval)) { |
|
11331
4fdc9c1ecaf6
Patch by Tim Peters fixing PR#89:
Guido van Rossum <guido@python.org>
parents:
9969
diff
changeset
|
109 PyErr_SetString(PyExc_OverflowError, |
|
4fdc9c1ecaf6
Patch by Tim Peters fixing PR#89:
Guido van Rossum <guido@python.org>
parents:
9969
diff
changeset
|
110 "cannot convert float infinity to long"); |
|
4fdc9c1ecaf6
Patch by Tim Peters fixing PR#89:
Guido van Rossum <guido@python.org>
parents:
9969
diff
changeset
|
111 return NULL; |
|
4fdc9c1ecaf6
Patch by Tim Peters fixing PR#89:
Guido van Rossum <guido@python.org>
parents:
9969
diff
changeset
|
112 } |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
113 if (dval < 0.0) { |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
114 neg = 1; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
115 dval = -dval; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
116 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
117 frac = frexp(dval, &expo); /* dval = frac*2**expo; 0.0 <= frac < 1.0 */ |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
118 if (expo <= 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
119 return PyLong_FromLong(0L); |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
120 ndig = (expo-1) / SHIFT + 1; /* Number of 'digits' in result */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
121 v = _PyLong_New(ndig); |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
122 if (v == NULL) |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
123 return NULL; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
124 frac = ldexp(frac, (expo-1) % SHIFT + 1); |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
125 for (i = ndig; --i >= 0; ) { |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
126 long bits = (long)frac; |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
127 v->ob_digit[i] = (digit) bits; |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
128 frac = frac - (double)bits; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
129 frac = ldexp(frac, SHIFT); |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
130 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
131 if (neg) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
132 v->ob_size = -(v->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
133 return (PyObject *)v; |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
134 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
135 |
| 230 | 136 /* Get a C long int from a long int object. |
| 137 Returns -1 and sets an error condition if overflow occurs. */ | |
| 138 | |
| 139 long | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
140 PyLong_AsLong(PyObject *vv) |
| 230 | 141 { |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
142 /* This version by Tim Peters */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
143 register PyLongObject *v; |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
144 unsigned long x, prev; |
| 230 | 145 int i, sign; |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
146 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
147 if (vv == NULL || !PyLong_Check(vv)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
148 PyErr_BadInternalCall(); |
| 230 | 149 return -1; |
| 150 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
151 v = (PyLongObject *)vv; |
| 230 | 152 i = v->ob_size; |
| 153 sign = 1; | |
| 154 x = 0; | |
| 155 if (i < 0) { | |
| 156 sign = -1; | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
157 i = -(i); |
| 230 | 158 } |
| 159 while (--i >= 0) { | |
| 160 prev = x; | |
| 161 x = (x << SHIFT) + v->ob_digit[i]; | |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
162 if ((x >> SHIFT) != prev) |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
163 goto overflow; |
| 230 | 164 } |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
165 /* Haven't lost any bits, but if the sign bit is set we're in |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
166 * trouble *unless* this is the min negative number. So, |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
167 * trouble iff sign bit set && (positive || some bit set other |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
168 * than the sign bit). |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
169 */ |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
170 if ((long)x < 0 && (sign > 0 || (x << 1) != 0)) |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
171 goto overflow; |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
172 return (long)x * sign; |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
173 |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
174 overflow: |
|
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
175 PyErr_SetString(PyExc_OverflowError, |
| 15318 | 176 "long int too large to convert"); |
|
8425
e2d41bf1a0f0
Subject: Buglet in PyLong_AsLong
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
177 return -1; |
| 230 | 178 } |
| 179 | |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
180 /* Get a C long int from a long int object. |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
181 Returns -1 and sets an error condition if overflow occurs. */ |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
182 |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
183 unsigned long |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
184 PyLong_AsUnsignedLong(PyObject *vv) |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
185 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
186 register PyLongObject *v; |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
187 unsigned long x, prev; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
188 int i; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
189 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
190 if (vv == NULL || !PyLong_Check(vv)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
191 PyErr_BadInternalCall(); |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
192 return (unsigned long) -1; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
193 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
194 v = (PyLongObject *)vv; |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
195 i = v->ob_size; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
196 x = 0; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
197 if (i < 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
198 PyErr_SetString(PyExc_OverflowError, |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
199 "can't convert negative value to unsigned long"); |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
200 return (unsigned long) -1; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
201 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
202 while (--i >= 0) { |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
203 prev = x; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
204 x = (x << SHIFT) + v->ob_digit[i]; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
205 if ((x >> SHIFT) != prev) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
206 PyErr_SetString(PyExc_OverflowError, |
| 15318 | 207 "long int too large to convert"); |
|
4870
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
208 return (unsigned long) -1; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
209 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
210 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
211 return x; |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
212 } |
|
68f4134869db
Added PyLong_FromUnsignedLong() and PyLong_AsUnsignedLong().
Guido van Rossum <guido@python.org>
parents:
4587
diff
changeset
|
213 |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4870
diff
changeset
|
214 /* Get a C double from a long int object. */ |
| 230 | 215 |
| 216 double | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
217 PyLong_AsDouble(PyObject *vv) |
| 230 | 218 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
219 register PyLongObject *v; |
| 230 | 220 double x; |
| 221 double multiplier = (double) (1L << SHIFT); | |
| 222 int i, sign; | |
| 223 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
224 if (vv == NULL || !PyLong_Check(vv)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
225 PyErr_BadInternalCall(); |
| 230 | 226 return -1; |
| 227 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
228 v = (PyLongObject *)vv; |
| 230 | 229 i = v->ob_size; |
| 230 sign = 1; | |
| 231 x = 0.0; | |
| 232 if (i < 0) { | |
| 233 sign = -1; | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
234 i = -(i); |
| 230 | 235 } |
| 236 while (--i >= 0) { | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
237 x = x*multiplier + (double)v->ob_digit[i]; |
| 230 | 238 } |
| 239 return x * sign; | |
| 240 } | |
| 241 | |
|
9123
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
242 /* Create a new long (or int) object from a C pointer */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
243 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
244 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
245 PyLong_FromVoidPtr(void *p) |
|
9123
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
246 { |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
247 #if SIZEOF_VOID_P == SIZEOF_LONG |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
248 return PyInt_FromLong((long)p); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
249 #else |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
250 /* optimize null pointers */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
251 if ( p == NULL ) |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
252 return PyInt_FromLong(0); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
253 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
254 /* we can assume that HAVE_LONG_LONG is true. if not, then the |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
255 configuration process should have bailed (having big pointers |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
256 without long longs seems non-sensical) */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
257 return PyLong_FromLongLong((LONG_LONG)p); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
258 #endif /* SIZEOF_VOID_P == SIZEOF_LONG */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
259 } |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
260 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
261 /* Get a C pointer from a long object (or an int object in some cases) */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
262 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
263 void * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
264 PyLong_AsVoidPtr(PyObject *vv) |
|
9123
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
265 { |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
266 /* This function will allow int or long objects. If vv is neither, |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
267 then the PyLong_AsLong*() functions will raise the exception: |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
268 PyExc_SystemError, "bad argument to internal function" |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
269 */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
270 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
271 #if SIZEOF_VOID_P == SIZEOF_LONG |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
272 long x; |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
273 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
274 if ( PyInt_Check(vv) ) |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
275 x = PyInt_AS_LONG(vv); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
276 else |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
277 x = PyLong_AsLong(vv); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
278 #else |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
279 /* we can assume that HAVE_LONG_LONG is true. if not, then the |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
280 configuration process should have bailed (having big pointers |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
281 without long longs seems non-sensical) */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
282 LONG_LONG x; |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
283 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
284 if ( PyInt_Check(vv) ) |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
285 x = PyInt_AS_LONG(vv); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
286 else |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
287 x = PyLong_AsLongLong(vv); |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
288 #endif /* SIZEOF_VOID_P == SIZEOF_LONG */ |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
289 |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
290 if (x == -1 && PyErr_Occurred()) |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
291 return NULL; |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
292 return (void *)x; |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
293 } |
|
17d0c51e0887
Patches from Greg Stein to support 'P' format in struct module's
Guido van Rossum <guido@python.org>
parents:
9094
diff
changeset
|
294 |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
295 #ifdef HAVE_LONG_LONG |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
296 /* |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
297 * LONG_LONG support by Chris Herborth (chrish@qnx.com) |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
298 * |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
299 * For better or worse :-), I tried to follow the coding style already |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
300 * here. |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
301 */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
302 |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
303 /* Create a new long int object from a C LONG_LONG int */ |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
304 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
305 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
306 PyLong_FromLongLong(LONG_LONG ival) |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
307 { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
308 #if SIZEOF_LONG_LONG == SIZEOF_LONG |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
309 /* In case the compiler is faking it. */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
310 return PyLong_FromLong( (long)ival ); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
311 #else |
|
12821
f2db60943d6b
Trent Mick <trentm@ActiveState.com>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
312 if ((LONG_LONG)LONG_MIN <= ival && ival <= (LONG_LONG)LONG_MAX) { |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
313 return PyLong_FromLong( (long)ival ); |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
314 } |
|
12821
f2db60943d6b
Trent Mick <trentm@ActiveState.com>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
315 else if (0 <= ival && ival <= (unsigned LONG_LONG)ULONG_MAX) { |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
316 return PyLong_FromUnsignedLong( (unsigned long)ival ); |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
317 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
318 else { |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
319 /* Assume a C LONG_LONG fits in at most 10 'digits'. |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
320 * Should be OK if we're assuming long fits in 5. |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
321 */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
322 PyLongObject *v = _PyLong_New(10); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
323 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
324 if (v != NULL) { |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
325 unsigned LONG_LONG t = ival; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
326 int i; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
327 if (ival < 0) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
328 t = -ival; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
329 v->ob_size = -(v->ob_size); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
330 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
331 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
332 for (i = 0; i < 10; i++) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
333 v->ob_digit[i] = (digit) (t & MASK); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
334 t >>= SHIFT; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
335 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
336 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
337 v = long_normalize(v); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
338 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
339 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
340 return (PyObject *)v; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
341 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
342 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
343 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
344 |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
345 /* Create a new long int object from a C unsigned LONG_LONG int */ |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
346 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
347 PyLong_FromUnsignedLongLong(unsigned LONG_LONG ival) |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
348 { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
349 #if SIZEOF_LONG_LONG == SIZEOF_LONG |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
350 /* In case the compiler is faking it. */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
351 return PyLong_FromUnsignedLong( (unsigned long)ival ); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
352 #else |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
353 if( ival <= (unsigned LONG_LONG)ULONG_MAX ) { |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
354 return PyLong_FromUnsignedLong( (unsigned long)ival ); |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
355 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
356 else { |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
357 /* Assume a C long fits in at most 10 'digits'. */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
358 PyLongObject *v = _PyLong_New(10); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
359 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
360 if (v != NULL) { |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
361 unsigned LONG_LONG t = ival; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
362 int i; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
363 for (i = 0; i < 10; i++) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
364 v->ob_digit[i] = (digit) (t & MASK); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
365 t >>= SHIFT; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
366 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
367 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
368 v = long_normalize(v); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
369 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
370 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
371 return (PyObject *)v; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
372 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
373 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
374 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
375 |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
376 /* Get a C LONG_LONG int from a long int object. |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
377 Returns -1 and sets an error condition if overflow occurs. */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
378 |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
379 LONG_LONG |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
380 PyLong_AsLongLong(PyObject *vv) |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
381 { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
382 #if SIZEOF_LONG_LONG == SIZEOF_LONG |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
383 /* In case the compiler is faking it. */ |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
384 return (LONG_LONG)PyLong_AsLong( vv ); |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
385 #else |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
386 register PyLongObject *v; |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
387 LONG_LONG x, prev; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
388 int i, sign; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
389 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
390 if (vv == NULL || !PyLong_Check(vv)) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
391 PyErr_BadInternalCall(); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
392 return -1; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
393 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
394 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
395 v = (PyLongObject *)vv; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
396 i = v->ob_size; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
397 sign = 1; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
398 x = 0; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
399 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
400 if (i < 0) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
401 sign = -1; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
402 i = -(i); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
403 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
404 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
405 while (--i >= 0) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
406 prev = x; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
407 x = (x << SHIFT) + v->ob_digit[i]; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
408 if ((x >> SHIFT) != prev) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
409 PyErr_SetString(PyExc_OverflowError, |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
410 "long int too long to convert"); |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
411 return -1; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
412 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
413 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
414 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
415 return x * sign; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
416 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
417 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
418 |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
419 unsigned LONG_LONG |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
420 PyLong_AsUnsignedLongLong(PyObject *vv) |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
421 { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
422 #if SIZEOF_LONG_LONG == 4 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
423 /* In case the compiler is faking it. */ |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
424 return (unsigned LONG_LONG)PyLong_AsUnsignedLong( vv ); |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
425 #else |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
426 register PyLongObject *v; |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
427 unsigned LONG_LONG x, prev; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
428 int i; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
429 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
430 if (vv == NULL || !PyLong_Check(vv)) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
431 PyErr_BadInternalCall(); |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
432 return (unsigned LONG_LONG) -1; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
433 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
434 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
435 v = (PyLongObject *)vv; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
436 i = v->ob_size; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
437 x = 0; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
438 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
439 if (i < 0) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
440 PyErr_SetString(PyExc_OverflowError, |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
441 "can't convert negative value to unsigned long"); |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
442 return (unsigned LONG_LONG) -1; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
443 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
444 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
445 while (--i >= 0) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
446 prev = x; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
447 x = (x << SHIFT) + v->ob_digit[i]; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
448 if ((x >> SHIFT) != prev) { |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
449 PyErr_SetString(PyExc_OverflowError, |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
450 "long int too long to convert"); |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8933
diff
changeset
|
451 return (unsigned LONG_LONG) -1; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
452 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
453 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
454 |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
455 return x; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
456 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
457 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
458 #endif /* HAVE_LONG_LONG */ |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8808
diff
changeset
|
459 |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
460 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
461 static int |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
462 convert_binop(PyObject *v, PyObject *w, PyLongObject **a, PyLongObject **b) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
463 if (PyLong_Check(v)) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
464 *a = (PyLongObject *) v; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
465 Py_INCREF(v); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
466 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
467 else if (PyInt_Check(v)) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
468 *a = (PyLongObject *) PyLong_FromLong(PyInt_AS_LONG(v)); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
469 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
470 else { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
471 return 0; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
472 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
473 if (PyLong_Check(w)) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
474 *b = (PyLongObject *) w; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
475 Py_INCREF(w); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
476 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
477 else if (PyInt_Check(w)) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
478 *b = (PyLongObject *) PyLong_FromLong(PyInt_AS_LONG(w)); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
479 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
480 else { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
481 Py_DECREF(*a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
482 return 0; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
483 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
484 return 1; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
485 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
486 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
487 #define CONVERT_BINOP(v, w, a, b) \ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
488 if (!convert_binop(v, w, a, b)) { \ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
489 Py_INCREF(Py_NotImplemented); \ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
490 return Py_NotImplemented; \ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
491 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
492 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
493 |
| 230 | 494 /* Multiply by a single digit, ignoring the sign. */ |
| 495 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
496 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
497 mul1(PyLongObject *a, wdigit n) |
| 230 | 498 { |
| 499 return muladd1(a, n, (digit)0); | |
| 500 } | |
| 501 | |
| 502 /* Multiply by a single digit and add a single digit, ignoring the sign. */ | |
| 503 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
504 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
505 muladd1(PyLongObject *a, wdigit n, wdigit extra) |
| 230 | 506 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
507 int size_a = ABS(a->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
508 PyLongObject *z = _PyLong_New(size_a+1); |
| 230 | 509 twodigits carry = extra; |
| 510 int i; | |
| 511 | |
| 512 if (z == NULL) | |
| 513 return NULL; | |
| 514 for (i = 0; i < size_a; ++i) { | |
| 515 carry += (twodigits)a->ob_digit[i] * n; | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
516 z->ob_digit[i] = (digit) (carry & MASK); |
| 230 | 517 carry >>= SHIFT; |
| 518 } | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
519 z->ob_digit[i] = (digit) carry; |
| 230 | 520 return long_normalize(z); |
| 521 } | |
| 522 | |
| 523 /* Divide a long integer by a digit, returning both the quotient | |
| 524 (as function result) and the remainder (through *prem). | |
| 525 The sign of a is ignored; n should not be zero. */ | |
| 526 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
527 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
528 divrem1(PyLongObject *a, wdigit n, digit *prem) |
| 230 | 529 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
530 int size = ABS(a->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
531 PyLongObject *z; |
| 230 | 532 int i; |
| 533 twodigits rem = 0; | |
| 534 | |
| 535 assert(n > 0 && n <= MASK); | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
536 z = _PyLong_New(size); |
| 230 | 537 if (z == NULL) |
| 538 return NULL; | |
| 539 for (i = size; --i >= 0; ) { | |
| 540 rem = (rem << SHIFT) + a->ob_digit[i]; | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
541 z->ob_digit[i] = (digit) (rem/n); |
| 230 | 542 rem %= n; |
| 543 } | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
544 *prem = (digit) rem; |
| 230 | 545 return long_normalize(z); |
| 546 } | |
| 547 | |
| 548 /* Convert a long int object to a string, using a given conversion base. | |
|
406
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
549 Return a string object. |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
550 If base is 8 or 16, add the proper prefix '0' or '0x'. */ |
| 230 | 551 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
552 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
553 long_format(PyObject *aa, int base, int addL) |
| 230 | 554 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
555 register PyLongObject *a = (PyLongObject *)aa; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
556 PyStringObject *str; |
| 230 | 557 int i; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
558 int size_a = ABS(a->ob_size); |
| 230 | 559 char *p; |
| 560 int bits; | |
| 561 char sign = '\0'; | |
| 613 | 562 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
563 if (a == NULL || !PyLong_Check(a)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
564 PyErr_BadInternalCall(); |
| 613 | 565 return NULL; |
| 566 } | |
| 230 | 567 assert(base >= 2 && base <= 36); |
| 568 | |
| 569 /* Compute a rough upper bound for the length of the string */ | |
| 570 i = base; | |
| 571 bits = 0; | |
| 572 while (i > 1) { | |
| 573 ++bits; | |
| 574 i >>= 1; | |
| 575 } | |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
576 i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
577 str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i); |
| 230 | 578 if (str == NULL) |
| 579 return NULL; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
580 p = PyString_AS_STRING(str) + i; |
| 230 | 581 *p = '\0'; |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
582 if (addL) |
|
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
583 *--p = 'L'; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
584 if (a->ob_size < 0) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
585 sign = '-'; |
| 230 | 586 |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
587 if (a->ob_size == 0) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
588 *--p = '0'; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
589 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
590 else if ((base & (base - 1)) == 0) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
591 /* JRH: special case for power-of-2 bases */ |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
592 twodigits temp = a->ob_digit[0]; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
593 int bitsleft = SHIFT; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
594 int rem; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
595 int last = abs(a->ob_size); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
596 int basebits = 1; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
597 i = base; |
|
13423
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
598 while ((i >>= 1) > 1) |
|
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
599 ++basebits; |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
600 |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
601 i = 0; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
602 for (;;) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
603 while (bitsleft >= basebits) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
604 if ((temp == 0) && (i >= last - 1)) break; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
605 rem = temp & (base - 1); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
606 if (rem < 10) |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
607 rem += '0'; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
608 else |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
609 rem += 'A' - 10; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
610 assert(p > PyString_AS_STRING(str)); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
611 *--p = (char) rem; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
612 bitsleft -= basebits; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
613 temp >>= basebits; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
614 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
615 if (++i >= last) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
616 if (temp == 0) break; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
617 bitsleft = 99; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
618 /* loop again to pick up final digits */ |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
619 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
620 else { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
621 temp = (a->ob_digit[i] << bitsleft) | temp; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
622 bitsleft += SHIFT; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
623 } |
| 230 | 624 } |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
625 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
626 else { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
627 Py_INCREF(a); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
628 do { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
629 digit rem; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
630 PyLongObject *temp = divrem1(a, (digit)base, &rem); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
631 if (temp == NULL) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
632 Py_DECREF(a); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
633 Py_DECREF(str); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
634 return NULL; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
635 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
636 if (rem < 10) |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
637 rem += '0'; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
638 else |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
639 rem += 'A'-10; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
640 assert(p > PyString_AS_STRING(str)); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
641 *--p = (char) rem; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
642 Py_DECREF(a); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
643 a = temp; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
644 SIGCHECK({ |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
645 Py_DECREF(a); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
646 Py_DECREF(str); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
647 return NULL; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
648 }) |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
649 } while (ABS(a->ob_size) != 0); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
650 Py_DECREF(a); |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
651 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
652 |
|
958
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
653 if (base == 8) { |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
654 if (size_a != 0) |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
655 *--p = '0'; |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
656 } |
|
406
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
657 else if (base == 16) { |
|
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
658 *--p = 'x'; |
|
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
659 *--p = '0'; |
|
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
660 } |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
661 else if (base != 10) { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
662 *--p = '#'; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
663 *--p = '0' + base%10; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
664 if (base > 10) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
665 *--p = '0' + base/10; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
666 } |
| 230 | 667 if (sign) |
| 668 *--p = sign; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
669 if (p != PyString_AS_STRING(str)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
670 char *q = PyString_AS_STRING(str); |
| 230 | 671 assert(p > q); |
| 672 do { | |
| 673 } while ((*q++ = *p++) != '\0'); | |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
674 q--; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
675 _PyString_Resize((PyObject **)&str, |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
676 (int) (q - PyString_AS_STRING(str))); |
| 230 | 677 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
678 return (PyObject *)str; |
| 230 | 679 } |
| 680 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
681 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
682 PyLong_FromString(char *str, char **pend, int base) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
683 { |
| 230 | 684 int sign = 1; |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
685 char *start, *orig_str = str; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
686 PyLongObject *z; |
| 230 | 687 |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
688 if ((base != 0 && base < 2) || base > 36) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
689 PyErr_SetString(PyExc_ValueError, |
| 15318 | 690 "long() arg 2 must be >= 2 and <= 36"); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
691 return NULL; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
692 } |
|
2308
14b126d0b5be
use Py_CHARMASK; and don't check for neg. float to the float power here
Guido van Rossum <guido@python.org>
parents:
2158
diff
changeset
|
693 while (*str != '\0' && isspace(Py_CHARMASK(*str))) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
694 str++; |
| 230 | 695 if (*str == '+') |
| 696 ++str; | |
| 697 else if (*str == '-') { | |
| 698 ++str; | |
| 699 sign = -1; | |
| 700 } | |
|
2308
14b126d0b5be
use Py_CHARMASK; and don't check for neg. float to the float power here
Guido van Rossum <guido@python.org>
parents:
2158
diff
changeset
|
701 while (*str != '\0' && isspace(Py_CHARMASK(*str))) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
702 str++; |
| 230 | 703 if (base == 0) { |
| 704 if (str[0] != '0') | |
| 705 base = 10; | |
| 706 else if (str[1] == 'x' || str[1] == 'X') | |
| 707 base = 16; | |
| 708 else | |
| 709 base = 8; | |
| 710 } | |
| 711 if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) | |
| 712 str += 2; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
713 z = _PyLong_New(0); |
|
8533
e5d06a602469
Add check in long-to-int conversion for at least one digit.
Guido van Rossum <guido@python.org>
parents:
8425
diff
changeset
|
714 start = str; |
| 230 | 715 for ( ; z != NULL; ++str) { |
| 716 int k = -1; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
717 PyLongObject *temp; |
| 230 | 718 |
| 719 if (*str <= '9') | |
| 720 k = *str - '0'; | |
| 721 else if (*str >= 'a') | |
| 722 k = *str - 'a' + 10; | |
| 723 else if (*str >= 'A') | |
| 724 k = *str - 'A' + 10; | |
| 725 if (k < 0 || k >= base) | |
| 726 break; | |
| 727 temp = muladd1(z, (digit)base, (digit)k); | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
728 Py_DECREF(z); |
| 230 | 729 z = temp; |
| 730 } | |
|
8808
78785985a2ab
Fix a potential problem in PyLong_FromString(): could fall through the
Guido van Rossum <guido@python.org>
parents:
8533
diff
changeset
|
731 if (z == NULL) |
|
78785985a2ab
Fix a potential problem in PyLong_FromString(): could fall through the
Guido van Rossum <guido@python.org>
parents:
8533
diff
changeset
|
732 return NULL; |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
733 if (str == start) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
734 goto onError; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
735 if (sign < 0 && z != NULL && z->ob_size != 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
736 z->ob_size = -(z->ob_size); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
737 if (*str == 'L' || *str == 'l') |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
738 str++; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
739 while (*str && isspace(Py_CHARMASK(*str))) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
740 str++; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
741 if (*str != '\0') |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
742 goto onError; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
743 if (pend) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
744 *pend = str; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
745 return (PyObject *) z; |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
746 |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
747 onError: |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
748 PyErr_Format(PyExc_ValueError, |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
749 "invalid literal for long(): %.200s", orig_str); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
750 Py_XDECREF(z); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
751 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
752 } |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
753 |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
754 PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
755 PyLong_FromUnicode(Py_UNICODE *u, int length, int base) |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
756 { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
757 char buffer[256]; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
758 |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
759 if (length >= sizeof(buffer)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
760 PyErr_SetString(PyExc_ValueError, |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
761 "long() literal too large to convert"); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
762 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
763 } |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
764 if (PyUnicode_EncodeDecimal(u, length, buffer, NULL)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
765 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
766 |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11628
diff
changeset
|
767 return PyLong_FromString(buffer, NULL, base); |
| 230 | 768 } |
| 769 | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
770 /* forward */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
771 static PyLongObject *x_divrem |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
772 (PyLongObject *, PyLongObject *, PyLongObject **); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
773 static PyObject *long_pos(PyLongObject *); |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
774 static int long_divrem(PyLongObject *, PyLongObject *, |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
775 PyLongObject **, PyLongObject **); |
| 230 | 776 |
| 777 /* Long division with remainder, top-level routine */ | |
| 778 | |
| 613 | 779 static int |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
780 long_divrem(PyLongObject *a, PyLongObject *b, |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
781 PyLongObject **pdiv, PyLongObject **prem) |
| 230 | 782 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
783 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
784 PyLongObject *z; |
| 230 | 785 |
| 786 if (size_b == 0) { | |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
787 PyErr_SetString(PyExc_ZeroDivisionError, |
| 15318 | 788 "long division or modulo by zero"); |
| 613 | 789 return -1; |
| 230 | 790 } |
| 791 if (size_a < size_b || | |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
792 (size_a == size_b && |
|
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
793 a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) { |
| 230 | 794 /* |a| < |b|. */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
795 *pdiv = _PyLong_New(0); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
796 Py_INCREF(a); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
797 *prem = (PyLongObject *) a; |
| 613 | 798 return 0; |
| 230 | 799 } |
| 800 if (size_b == 1) { | |
| 801 digit rem = 0; | |
| 802 z = divrem1(a, b->ob_digit[0], &rem); | |
| 613 | 803 if (z == NULL) |
| 804 return -1; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
805 *prem = (PyLongObject *) PyLong_FromLong((long)rem); |
| 230 | 806 } |
| 613 | 807 else { |
| 230 | 808 z = x_divrem(a, b, prem); |
| 613 | 809 if (z == NULL) |
| 810 return -1; | |
| 811 } | |
| 230 | 812 /* Set the signs. |
| 813 The quotient z has the sign of a*b; | |
| 814 the remainder r has the sign of a, | |
| 815 so a = b*z + r. */ | |
| 613 | 816 if ((a->ob_size < 0) != (b->ob_size < 0)) |
| 817 z->ob_size = -(z->ob_size); | |
| 818 if (a->ob_size < 0 && (*prem)->ob_size != 0) | |
| 819 (*prem)->ob_size = -((*prem)->ob_size); | |
| 820 *pdiv = z; | |
| 821 return 0; | |
| 230 | 822 } |
| 823 | |
| 242 | 824 /* Unsigned long division with remainder -- the algorithm */ |
| 230 | 825 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
826 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
827 x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem) |
| 230 | 828 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
829 int size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size); |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
830 digit d = (digit) ((twodigits)BASE / (w1->ob_digit[size_w-1] + 1)); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
831 PyLongObject *v = mul1(v1, d); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
832 PyLongObject *w = mul1(w1, d); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
833 PyLongObject *a; |
| 230 | 834 int j, k; |
| 835 | |
| 836 if (v == NULL || w == NULL) { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
837 Py_XDECREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
838 Py_XDECREF(w); |
| 230 | 839 return NULL; |
| 840 } | |
| 841 | |
| 842 assert(size_v >= size_w && size_w > 1); /* Assert checks by div() */ | |
| 242 | 843 assert(v->ob_refcnt == 1); /* Since v will be used as accumulator! */ |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
844 assert(size_w == ABS(w->ob_size)); /* That's how d was calculated */ |
| 230 | 845 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
846 size_v = ABS(v->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
847 a = _PyLong_New(size_v - size_w + 1); |
| 230 | 848 |
| 849 for (j = size_v, k = a->ob_size-1; a != NULL && k >= 0; --j, --k) { | |
| 850 digit vj = (j >= size_v) ? 0 : v->ob_digit[j]; | |
| 851 twodigits q; | |
| 242 | 852 stwodigits carry = 0; |
| 230 | 853 int i; |
| 854 | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
855 SIGCHECK({ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
856 Py_DECREF(a); |
| 230 | 857 a = NULL; |
| 858 break; | |
| 242 | 859 }) |
| 230 | 860 if (vj == w->ob_digit[size_w-1]) |
| 861 q = MASK; | |
| 862 else | |
| 863 q = (((twodigits)vj << SHIFT) + v->ob_digit[j-1]) / | |
| 864 w->ob_digit[size_w-1]; | |
| 865 | |
| 866 while (w->ob_digit[size_w-2]*q > | |
| 867 (( | |
| 868 ((twodigits)vj << SHIFT) | |
| 869 + v->ob_digit[j-1] | |
| 870 - q*w->ob_digit[size_w-1] | |
| 871 ) << SHIFT) | |
| 872 + v->ob_digit[j-2]) | |
| 873 --q; | |
| 874 | |
| 875 for (i = 0; i < size_w && i+k < size_v; ++i) { | |
| 876 twodigits z = w->ob_digit[i] * q; | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
877 digit zz = (digit) (z >> SHIFT); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
878 carry += v->ob_digit[i+k] - z |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
879 + ((twodigits)zz << SHIFT); |
| 230 | 880 v->ob_digit[i+k] = carry & MASK; |
|
13423
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
881 carry = Py_ARITHMETIC_RIGHT_SHIFT(BASE_TWODIGITS_TYPE, |
|
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
882 carry, SHIFT); |
|
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
883 carry -= zz; |
| 230 | 884 } |
| 885 | |
| 886 if (i+k < size_v) { | |
| 887 carry += v->ob_digit[i+k]; | |
| 888 v->ob_digit[i+k] = 0; | |
| 889 } | |
| 890 | |
| 891 if (carry == 0) | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
892 a->ob_digit[k] = (digit) q; |
| 230 | 893 else { |
| 894 assert(carry == -1); | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
895 a->ob_digit[k] = (digit) q-1; |
| 230 | 896 carry = 0; |
| 897 for (i = 0; i < size_w && i+k < size_v; ++i) { | |
| 898 carry += v->ob_digit[i+k] + w->ob_digit[i]; | |
| 899 v->ob_digit[i+k] = carry & MASK; | |
|
13423
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
900 carry = Py_ARITHMETIC_RIGHT_SHIFT( |
|
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
901 BASE_TWODIGITS_TYPE, |
|
a87803eb9dfb
Cray J90 fixes for long ints.
Tim Peters <tim.peters@gmail.com>
parents:
13420
diff
changeset
|
902 carry, SHIFT); |
| 230 | 903 } |
| 904 } | |
| 905 } /* for j, k */ | |
| 906 | |
|
2111
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
907 if (a == NULL) |
|
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
908 *prem = NULL; |
|
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
909 else { |
| 230 | 910 a = long_normalize(a); |
| 613 | 911 *prem = divrem1(v, d, &d); |
| 912 /* d receives the (unused) remainder */ | |
| 913 if (*prem == NULL) { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
914 Py_DECREF(a); |
| 613 | 915 a = NULL; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
916 } |
| 230 | 917 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
918 Py_DECREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
919 Py_DECREF(w); |
| 230 | 920 return a; |
| 921 } | |
| 922 | |
| 923 /* Methods */ | |
| 924 | |
| 925 static void | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
926 long_dealloc(PyObject *v) |
| 230 | 927 { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12341
diff
changeset
|
928 PyObject_DEL(v); |
| 230 | 929 } |
| 930 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
931 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
932 long_repr(PyObject *v) |
| 230 | 933 { |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
934 return long_format(v, 10, 1); |
|
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
935 } |
|
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
936 |
|
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
937 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
938 long_str(PyObject *v) |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
939 { |
|
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
940 return long_format(v, 10, 0); |
| 230 | 941 } |
| 942 | |
| 943 static int | |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
944 long_compare(PyLongObject *a, PyLongObject *b) |
| 230 | 945 { |
| 946 int sign; | |
| 947 | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
948 if (a->ob_size != b->ob_size) { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
949 if (ABS(a->ob_size) == 0 && ABS(b->ob_size) == 0) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
950 sign = 0; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
951 else |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
952 sign = a->ob_size - b->ob_size; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
953 } |
| 230 | 954 else { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
955 int i = ABS(a->ob_size); |
| 230 | 956 while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i]) |
| 957 ; | |
| 958 if (i < 0) | |
| 959 sign = 0; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
960 else { |
| 230 | 961 sign = (int)a->ob_digit[i] - (int)b->ob_digit[i]; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
962 if (a->ob_size < 0) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
963 sign = -sign; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
964 } |
| 230 | 965 } |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
966 return sign < 0 ? -1 : sign > 0 ? 1 : 0; |
| 230 | 967 } |
| 968 | |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
969 /* Needed for the new style number compare slots */ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
970 static PyObject * |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
971 long_cmp(PyObject *v, PyObject *w) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
972 { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
973 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
974 int c; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
975 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
976 c = long_compare(a, b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
977 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
978 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
979 return PyInt_FromLong(c); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
980 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
981 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
982 static long |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
983 long_hash(PyLongObject *v) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
984 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
985 long x; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
986 int i, sign; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
987 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
988 /* This is designed so that Python ints and longs with the |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
989 same value hash to the same value, otherwise comparisons |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
990 of mapping keys will turn out weird */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
991 i = v->ob_size; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
992 sign = 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
993 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
994 if (i < 0) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
995 sign = -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
996 i = -(i); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
997 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
998 while (--i >= 0) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
999 /* Force a 32-bit circular shift */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1000 x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) & MASK); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1001 x += v->ob_digit[i]; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1002 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1003 x = x * sign; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1004 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1005 x = -2; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1006 return x; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1007 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1008 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1009 |
| 230 | 1010 /* Add the absolute values of two long integers. */ |
| 1011 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1012 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1013 x_add(PyLongObject *a, PyLongObject *b) |
| 230 | 1014 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1015 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1016 PyLongObject *z; |
| 230 | 1017 int i; |
| 1018 digit carry = 0; | |
| 1019 | |
| 1020 /* Ensure a is the larger of the two: */ | |
| 1021 if (size_a < size_b) { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1022 { PyLongObject *temp = a; a = b; b = temp; } |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1023 { int size_temp = size_a; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1024 size_a = size_b; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1025 size_b = size_temp; } |
| 230 | 1026 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1027 z = _PyLong_New(size_a+1); |
| 230 | 1028 if (z == NULL) |
| 1029 return NULL; | |
| 1030 for (i = 0; i < size_b; ++i) { | |
| 1031 carry += a->ob_digit[i] + b->ob_digit[i]; | |
| 1032 z->ob_digit[i] = carry & MASK; | |
| 1033 carry >>= SHIFT; | |
| 1034 } | |
| 1035 for (; i < size_a; ++i) { | |
| 1036 carry += a->ob_digit[i]; | |
| 1037 z->ob_digit[i] = carry & MASK; | |
| 1038 carry >>= SHIFT; | |
| 1039 } | |
| 1040 z->ob_digit[i] = carry; | |
| 1041 return long_normalize(z); | |
| 1042 } | |
| 1043 | |
| 1044 /* Subtract the absolute values of two integers. */ | |
| 1045 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1046 static PyLongObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1047 x_sub(PyLongObject *a, PyLongObject *b) |
| 230 | 1048 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1049 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1050 PyLongObject *z; |
| 230 | 1051 int i; |
| 1052 int sign = 1; | |
| 1053 digit borrow = 0; | |
| 1054 | |
| 1055 /* Ensure a is the larger of the two: */ | |
| 1056 if (size_a < size_b) { | |
| 1057 sign = -1; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1058 { PyLongObject *temp = a; a = b; b = temp; } |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1059 { int size_temp = size_a; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1060 size_a = size_b; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1061 size_b = size_temp; } |
| 230 | 1062 } |
| 1063 else if (size_a == size_b) { | |
| 1064 /* Find highest digit where a and b differ: */ | |
| 1065 i = size_a; | |
| 1066 while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i]) | |
| 1067 ; | |
| 1068 if (i < 0) | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1069 return _PyLong_New(0); |
| 230 | 1070 if (a->ob_digit[i] < b->ob_digit[i]) { |
| 1071 sign = -1; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1072 { PyLongObject *temp = a; a = b; b = temp; } |
| 230 | 1073 } |
| 1074 size_a = size_b = i+1; | |
| 1075 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1076 z = _PyLong_New(size_a); |
| 230 | 1077 if (z == NULL) |
| 1078 return NULL; | |
| 1079 for (i = 0; i < size_b; ++i) { | |
| 1080 /* The following assumes unsigned arithmetic | |
| 1081 works module 2**N for some N>SHIFT. */ | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1082 borrow = a->ob_digit[i] - b->ob_digit[i] - borrow; |
| 230 | 1083 z->ob_digit[i] = borrow & MASK; |
| 1084 borrow >>= SHIFT; | |
| 1085 borrow &= 1; /* Keep only one sign bit */ | |
| 1086 } | |
| 1087 for (; i < size_a; ++i) { | |
| 1088 borrow = a->ob_digit[i] - borrow; | |
| 1089 z->ob_digit[i] = borrow & MASK; | |
| 1090 borrow >>= SHIFT; | |
|
13420
d3f1eefdcb3a
The tail end of x_sub implicitly assumed that an unsigned short
Tim Peters <tim.peters@gmail.com>
parents:
13418
diff
changeset
|
1091 borrow &= 1; /* Keep only one sign bit */ |
| 230 | 1092 } |
| 1093 assert(borrow == 0); | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1094 if (sign < 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1095 z->ob_size = -(z->ob_size); |
| 230 | 1096 return long_normalize(z); |
| 1097 } | |
| 1098 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1099 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1100 long_add(PyLongObject *v, PyLongObject *w) |
| 230 | 1101 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1102 PyLongObject *a, *b, *z; |
| 230 | 1103 |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1104 CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1105 |
| 230 | 1106 if (a->ob_size < 0) { |
| 1107 if (b->ob_size < 0) { | |
| 1108 z = x_add(a, b); | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1109 if (z != NULL && z->ob_size != 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1110 z->ob_size = -(z->ob_size); |
| 230 | 1111 } |
| 1112 else | |
| 1113 z = x_sub(b, a); | |
| 1114 } | |
| 1115 else { | |
| 1116 if (b->ob_size < 0) | |
| 1117 z = x_sub(a, b); | |
| 1118 else | |
| 1119 z = x_add(a, b); | |
| 1120 } | |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1121 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1122 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1123 return (PyObject *)z; |
| 230 | 1124 } |
| 1125 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1126 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1127 long_sub(PyLongObject *v, PyLongObject *w) |
| 230 | 1128 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1129 PyLongObject *a, *b, *z; |
| 230 | 1130 |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1131 CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1132 |
| 230 | 1133 if (a->ob_size < 0) { |
| 1134 if (b->ob_size < 0) | |
| 1135 z = x_sub(a, b); | |
| 1136 else | |
| 1137 z = x_add(a, b); | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1138 if (z != NULL && z->ob_size != 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1139 z->ob_size = -(z->ob_size); |
| 230 | 1140 } |
| 1141 else { | |
| 1142 if (b->ob_size < 0) | |
| 1143 z = x_add(a, b); | |
| 1144 else | |
| 1145 z = x_sub(a, b); | |
| 1146 } | |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1147 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1148 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1149 return (PyObject *)z; |
| 230 | 1150 } |
| 1151 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1152 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1153 long_repeat(PyObject *v, PyLongObject *w) |
| 230 | 1154 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1155 /* sequence * long */ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1156 long n = PyLong_AsLong((PyObject *) w); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1157 if (n == -1 && PyErr_Occurred()) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1158 return NULL; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1159 else |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1160 return (*v->ob_type->tp_as_sequence->sq_repeat)(v, n); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1161 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1162 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1163 static PyObject * |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1164 long_mul(PyLongObject *v, PyLongObject *w) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1165 { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1166 PyLongObject *a, *b, *z; |
| 230 | 1167 int size_a; |
| 1168 int size_b; | |
| 1169 int i; | |
| 1170 | |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1171 if (v->ob_type->tp_as_sequence && |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1172 v->ob_type->tp_as_sequence->sq_repeat) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1173 return long_repeat((PyObject *)v, w); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1174 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1175 else if (w->ob_type->tp_as_sequence && |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1176 w->ob_type->tp_as_sequence->sq_repeat) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1177 return long_repeat((PyObject *)w, v); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1178 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1179 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1180 CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1181 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1182 size_a = ABS(a->ob_size); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1183 size_b = ABS(b->ob_size); |
|
12341
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1184 if (size_a > size_b) { |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1185 /* we are faster with the small object on the left */ |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1186 int hold_sa = size_a; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1187 PyLongObject *hold_a = a; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1188 size_a = size_b; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1189 size_b = hold_sa; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1190 a = b; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1191 b = hold_a; |
|
fc557f431e87
Simple optimization by Christian Tismer, who gives credit to Lenny
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
1192 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1193 z = _PyLong_New(size_a + size_b); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1194 if (z == NULL) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1195 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1196 Py_DECREF(b); |
| 230 | 1197 return NULL; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1198 } |
| 230 | 1199 for (i = 0; i < z->ob_size; ++i) |
| 1200 z->ob_digit[i] = 0; | |
| 1201 for (i = 0; i < size_a; ++i) { | |
| 1202 twodigits carry = 0; | |
| 1203 twodigits f = a->ob_digit[i]; | |
| 1204 int j; | |
| 1205 | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1206 SIGCHECK({ |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1207 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1208 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1209 Py_DECREF(z); |
| 230 | 1210 return NULL; |
| 242 | 1211 }) |
| 230 | 1212 for (j = 0; j < size_b; ++j) { |
| 1213 carry += z->ob_digit[i+j] + b->ob_digit[j] * f; | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
1214 z->ob_digit[i+j] = (digit) (carry & MASK); |
| 230 | 1215 carry >>= SHIFT; |
| 1216 } | |
| 1217 for (; carry != 0; ++j) { | |
| 1218 assert(i+j < z->ob_size); | |
| 1219 carry += z->ob_digit[i+j]; | |
|
5288
0f1711b7d367
Tweaks to keep the Microsoft compiler quiet.
Guido van Rossum <guido@python.org>
parents:
5199
diff
changeset
|
1220 z->ob_digit[i+j] = (digit) (carry & MASK); |
| 230 | 1221 carry >>= SHIFT; |
| 1222 } | |
| 1223 } | |
| 1224 if (a->ob_size < 0) | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1225 z->ob_size = -(z->ob_size); |
| 230 | 1226 if (b->ob_size < 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1227 z->ob_size = -(z->ob_size); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1228 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1229 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1230 return (PyObject *) long_normalize(z); |
| 230 | 1231 } |
| 1232 | |
| 613 | 1233 /* The / and % operators are now defined in terms of divmod(). |
| 1234 The expression a mod b has the value a - b*floor(a/b). | |
| 1235 The long_divrem function gives the remainder after division of | |
| 230 | 1236 |a| by |b|, with the sign of a. This is also expressed |
| 1237 as a - b*trunc(a/b), if trunc truncates towards zero. | |
| 1238 Some examples: | |
| 1239 a b a rem b a mod b | |
| 1240 13 10 3 3 | |
| 1241 -13 10 -3 7 | |
| 1242 13 -10 3 -7 | |
| 1243 -13 -10 -3 -3 | |
| 1244 So, to get from rem to mod, we have to add b if a and b | |
| 242 | 1245 have different signs. We then subtract one from the 'div' |
| 1246 part of the outcome to keep the invariant intact. */ | |
| 230 | 1247 |
| 613 | 1248 static int |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1249 l_divmod(PyLongObject *v, PyLongObject *w, |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1250 PyLongObject **pdiv, PyLongObject **pmod) |
| 613 | 1251 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1252 PyLongObject *div, *mod; |
| 613 | 1253 |
| 1254 if (long_divrem(v, w, &div, &mod) < 0) | |
| 1255 return -1; | |
|
4587
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
1256 if ((mod->ob_size < 0 && w->ob_size > 0) || |
|
09d94e9eb101
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
1257 (mod->ob_size > 0 && w->ob_size < 0)) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1258 PyLongObject *temp; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1259 PyLongObject *one; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1260 temp = (PyLongObject *) long_add(mod, w); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1261 Py_DECREF(mod); |
| 613 | 1262 mod = temp; |
| 1263 if (mod == NULL) { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1264 Py_DECREF(div); |
| 613 | 1265 return -1; |
| 1266 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1267 one = (PyLongObject *) PyLong_FromLong(1L); |
| 613 | 1268 if (one == NULL || |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1269 (temp = (PyLongObject *) long_sub(div, one)) == NULL) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1270 Py_DECREF(mod); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1271 Py_DECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1272 Py_XDECREF(one); |
| 613 | 1273 return -1; |
| 1274 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1275 Py_DECREF(one); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1276 Py_DECREF(div); |
| 613 | 1277 div = temp; |
| 1278 } | |
| 1279 *pdiv = div; | |
| 1280 *pmod = mod; | |
| 1281 return 0; | |
| 1282 } | |
| 1283 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1284 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1285 long_div(PyObject *v, PyObject *w) |
| 613 | 1286 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1287 PyLongObject *a, *b, *div, *mod; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1288 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1289 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1290 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1291 if (l_divmod(a, b, &div, &mod) < 0) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1292 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1293 Py_DECREF(b); |
| 613 | 1294 return NULL; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1295 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1296 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1297 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1298 Py_DECREF(mod); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1299 return (PyObject *)div; |
| 613 | 1300 } |
| 1301 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1302 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1303 long_mod(PyObject *v, PyObject *w) |
| 613 | 1304 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1305 PyLongObject *a, *b, *div, *mod; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1306 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1307 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1308 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1309 if (l_divmod(a, b, &div, &mod) < 0) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1310 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1311 Py_DECREF(b); |
| 613 | 1312 return NULL; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1313 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1314 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1315 Py_DECREF(b); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1316 Py_DECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1317 return (PyObject *)mod; |
| 613 | 1318 } |
| 1319 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1320 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1321 long_divmod(PyObject *v, PyObject *w) |
| 230 | 1322 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1323 PyLongObject *a, *b, *div, *mod; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1324 PyObject *z; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1325 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1326 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1327 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1328 if (l_divmod(a, b, &div, &mod) < 0) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1329 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1330 Py_DECREF(b); |
| 230 | 1331 return NULL; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1332 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1333 z = PyTuple_New(2); |
| 230 | 1334 if (z != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1335 PyTuple_SetItem(z, 0, (PyObject *) div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1336 PyTuple_SetItem(z, 1, (PyObject *) mod); |
| 230 | 1337 } |
| 1338 else { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1339 Py_DECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1340 Py_DECREF(mod); |
| 230 | 1341 } |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1342 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1343 Py_DECREF(b); |
| 230 | 1344 return z; |
| 1345 } | |
| 1346 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1347 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1348 long_pow(PyObject *v, PyObject *w, PyObject *x) |
| 230 | 1349 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1350 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1351 PyObject *c; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1352 PyLongObject *z, *div, *mod; |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1353 int size_b, i; |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1354 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1355 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1356 if (PyLong_Check(x) || Py_None == x) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1357 c = x; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1358 Py_INCREF(x); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1359 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1360 else if (PyInt_Check(x)) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1361 c = PyLong_FromLong(PyInt_AS_LONG(x)); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1362 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1363 else { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1364 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1365 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1366 Py_INCREF(Py_NotImplemented); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1367 return Py_NotImplemented; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1368 } |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1369 |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1370 size_b = b->ob_size; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1371 if (size_b < 0) { |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1372 if (a->ob_size) |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1373 PyErr_SetString(PyExc_ValueError, |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1374 "long integer to a negative power"); |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1375 else |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1376 PyErr_SetString(PyExc_ZeroDivisionError, |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1377 "zero to a negative power"); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1378 z = NULL; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1379 goto error; |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1380 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1381 z = (PyLongObject *)PyLong_FromLong(1L); |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1382 for (i = 0; i < size_b; ++i) { |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1383 digit bi = b->ob_digit[i]; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1384 int j; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1385 |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1386 for (j = 0; j < SHIFT; ++j) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1387 PyLongObject *temp; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1388 |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1389 if (bi & 1) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1390 temp = (PyLongObject *)long_mul(z, a); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1391 Py_DECREF(z); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1392 if (c!=Py_None && temp!=NULL) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1393 if (l_divmod(temp,(PyLongObject *)c, |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1394 &div,&mod) < 0) { |
|
11380
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1395 Py_DECREF(temp); |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1396 z = NULL; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1397 goto error; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1398 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1399 Py_XDECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1400 Py_DECREF(temp); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1401 temp = mod; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1402 } |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1403 z = temp; |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1404 if (z == NULL) |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1405 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1406 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1407 bi >>= 1; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1408 if (bi == 0 && i+1 == size_b) |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1409 break; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1410 temp = (PyLongObject *)long_mul(a, a); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1411 Py_DECREF(a); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1412 if (c!=Py_None && temp!=NULL) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1413 if (l_divmod(temp, (PyLongObject *)c, &div, |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1414 &mod) < 0) { |
|
11380
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1415 Py_DECREF(temp); |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1416 z = NULL; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1417 goto error; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1418 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1419 Py_XDECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1420 Py_DECREF(temp); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1421 temp = mod; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1422 } |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1423 a = temp; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1424 if (a == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1425 Py_DECREF(z); |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1426 z = NULL; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1427 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1428 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1429 } |
|
2111
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
1430 if (a == NULL || z == NULL) |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1431 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1432 } |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1433 if (c!=Py_None && z!=NULL) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1434 if (l_divmod(z, (PyLongObject *)c, &div, &mod) < 0) { |
|
11380
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1435 Py_DECREF(z); |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1436 z = NULL; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1437 } |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1438 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1439 Py_XDECREF(div); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1440 Py_DECREF(z); |
|
11380
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1441 z = mod; |
|
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1442 } |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1443 } |
|
11380
3e3c71f4d2de
Fix PR#66. Solution: add error checking around l_divmod() calls in
Guido van Rossum <guido@python.org>
parents:
11331
diff
changeset
|
1444 error: |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1445 Py_XDECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1446 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1447 Py_DECREF(c); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1448 return (PyObject *)z; |
| 230 | 1449 } |
| 1450 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1451 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1452 long_invert(PyLongObject *v) |
| 230 | 1453 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1454 /* Implement ~x as -(x+1) */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1455 PyLongObject *x; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1456 PyLongObject *w; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1457 w = (PyLongObject *)PyLong_FromLong(1L); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1458 if (w == NULL) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1459 return NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1460 x = (PyLongObject *) long_add(v, w); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1461 Py_DECREF(w); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1462 if (x == NULL) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1463 return NULL; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1464 if (x->ob_size != 0) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1465 x->ob_size = -(x->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1466 return (PyObject *)x; |
| 230 | 1467 } |
| 1468 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1469 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1470 long_pos(PyLongObject *v) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1471 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1472 Py_INCREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1473 return (PyObject *)v; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1474 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1475 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1476 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1477 long_neg(PyLongObject *v) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1478 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1479 PyLongObject *z; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1480 int i, n; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1481 n = ABS(v->ob_size); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1482 if (n == 0) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1483 /* -0 == 0 */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1484 Py_INCREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1485 return (PyObject *) v; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1486 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1487 z = _PyLong_New(ABS(n)); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1488 if (z == NULL) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1489 return NULL; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1490 for (i = 0; i < n; i++) |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1491 z->ob_digit[i] = v->ob_digit[i]; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1492 z->ob_size = -(v->ob_size); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1493 return (PyObject *)z; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1494 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1495 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1496 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1497 long_abs(PyLongObject *v) |
| 230 | 1498 { |
| 1499 if (v->ob_size < 0) | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1500 return long_neg(v); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1501 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1502 Py_INCREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1503 return (PyObject *)v; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1504 } |
| 230 | 1505 } |
| 1506 | |
| 242 | 1507 static int |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1508 long_nonzero(PyLongObject *v) |
| 242 | 1509 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1510 return ABS(v->ob_size) != 0; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1511 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1512 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1513 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1514 long_rshift(PyLongObject *v, PyLongObject *w) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1515 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1516 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1517 PyLongObject *z = NULL; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1518 long shiftby; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1519 int newsize, wordshift, loshift, hishift, i, j; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1520 digit lomask, himask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1521 |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1522 CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1523 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1524 if (a->ob_size < 0) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1525 /* Right shifting negative numbers is harder */ |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1526 PyLongObject *a1, *a2; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1527 a1 = (PyLongObject *) long_invert(a); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1528 if (a1 == NULL) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1529 goto rshift_error; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1530 a2 = (PyLongObject *) long_rshift(a1, b); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1531 Py_DECREF(a1); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1532 if (a2 == NULL) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1533 goto rshift_error; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1534 z = (PyLongObject *) long_invert(a2); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1535 Py_DECREF(a2); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1536 } |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1537 else { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1538 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1539 shiftby = PyLong_AsLong((PyObject *)b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1540 if (shiftby == -1L && PyErr_Occurred()) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1541 goto rshift_error; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1542 if (shiftby < 0) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1543 PyErr_SetString(PyExc_ValueError, |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1544 "negative shift count"); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1545 goto rshift_error; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1546 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1547 wordshift = shiftby / SHIFT; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1548 newsize = ABS(a->ob_size) - wordshift; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1549 if (newsize <= 0) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1550 z = _PyLong_New(0); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1551 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1552 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1553 return (PyObject *)z; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1554 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1555 loshift = shiftby % SHIFT; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1556 hishift = SHIFT - loshift; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1557 lomask = ((digit)1 << hishift) - 1; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1558 himask = MASK ^ lomask; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1559 z = _PyLong_New(newsize); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1560 if (z == NULL) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1561 goto rshift_error; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1562 if (a->ob_size < 0) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1563 z->ob_size = -(z->ob_size); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1564 for (i = 0, j = wordshift; i < newsize; i++, j++) { |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1565 z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1566 if (i+1 < newsize) |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1567 z->ob_digit[i] |= |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1568 (a->ob_digit[j+1] << hishift) & himask; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1569 } |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1570 z = long_normalize(z); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1571 } |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1572 rshift_error: |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1573 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1574 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1575 return (PyObject *) z; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1576 |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1577 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1578 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1579 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1580 long_lshift(PyObject *v, PyObject *w) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1581 { |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1582 /* This version due to Tim Peters */ |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1583 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1584 PyLongObject *z = NULL; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1585 long shiftby; |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1586 int oldsize, newsize, wordshift, remshift, i, j; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1587 twodigits accum; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1588 |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1589 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1590 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1591 shiftby = PyLong_AsLong((PyObject *)b); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1592 if (shiftby == -1L && PyErr_Occurred()) |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1593 goto lshift_error; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1594 if (shiftby < 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1595 PyErr_SetString(PyExc_ValueError, "negative shift count"); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1596 goto lshift_error; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1597 } |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1598 if ((long)(int)shiftby != shiftby) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1599 PyErr_SetString(PyExc_ValueError, |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1600 "outrageous left shift count"); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1601 goto lshift_error; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1602 } |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1603 /* wordshift, remshift = divmod(shiftby, SHIFT) */ |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1604 wordshift = (int)shiftby / SHIFT; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1605 remshift = (int)shiftby - wordshift * SHIFT; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1606 |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1607 oldsize = ABS(a->ob_size); |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1608 newsize = oldsize + wordshift; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1609 if (remshift) |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1610 ++newsize; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1611 z = _PyLong_New(newsize); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1612 if (z == NULL) |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1613 goto lshift_error; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1614 if (a->ob_size < 0) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1615 z->ob_size = -(z->ob_size); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1616 for (i = 0; i < wordshift; i++) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1617 z->ob_digit[i] = 0; |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1618 accum = 0; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1619 for (i = wordshift, j = 0; j < oldsize; i++, j++) { |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1620 accum |= a->ob_digit[j] << remshift; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1621 z->ob_digit[i] = (digit)(accum & MASK); |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1622 accum >>= SHIFT; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1623 } |
|
5199
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1624 if (remshift) |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1625 z->ob_digit[newsize-1] = (digit)accum; |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1626 else |
|
7e380df00d00
New long_lshift, without restriction on size of shift count, by Tim Peters.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1627 assert(!accum); |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1628 z = long_normalize(z); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1629 lshift_error: |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1630 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1631 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1632 return (PyObject *) z; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1633 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1634 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1635 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1636 /* Bitwise and/xor/or operations */ |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1637 |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1638 #define MAX(x, y) ((x) < (y) ? (y) : (x)) |
|
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1639 #define MIN(x, y) ((x) > (y) ? (y) : (x)) |
|
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1640 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1641 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1642 long_bitwise(PyLongObject *a, |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1643 int op, /* '&', '|', '^' */ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1644 PyLongObject *b) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1645 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1646 digit maska, maskb; /* 0 or MASK */ |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1647 int negz; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1648 int size_a, size_b, size_z; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1649 PyLongObject *z; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1650 int i; |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1651 digit diga, digb; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1652 PyObject *v; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1653 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1654 if (a->ob_size < 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1655 a = (PyLongObject *) long_invert(a); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1656 maska = MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1657 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1658 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1659 Py_INCREF(a); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1660 maska = 0; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1661 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1662 if (b->ob_size < 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1663 b = (PyLongObject *) long_invert(b); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1664 maskb = MASK; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1665 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1666 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1667 Py_INCREF(b); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1668 maskb = 0; |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1669 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1670 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1671 negz = 0; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1672 switch (op) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1673 case '^': |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1674 if (maska != maskb) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1675 maska ^= MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1676 negz = -1; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1677 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1678 break; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1679 case '&': |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1680 if (maska && maskb) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1681 op = '|'; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1682 maska ^= MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1683 maskb ^= MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1684 negz = -1; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1685 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1686 break; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1687 case '|': |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1688 if (maska || maskb) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1689 op = '&'; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1690 maska ^= MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1691 maskb ^= MASK; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1692 negz = -1; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1693 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1694 break; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1695 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1696 |
|
8933
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1697 /* JRH: The original logic here was to allocate the result value (z) |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1698 as the longer of the two operands. However, there are some cases |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1699 where the result is guaranteed to be shorter than that: AND of two |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1700 positives, OR of two negatives: use the shorter number. AND with |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1701 mixed signs: use the positive number. OR with mixed signs: use the |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1702 negative number. After the transformations above, op will be '&' |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1703 iff one of these cases applies, and mask will be non-0 for operands |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1704 whose length should be ignored. |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1705 */ |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1706 |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1707 size_a = a->ob_size; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1708 size_b = b->ob_size; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1709 size_z = op == '&' |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1710 ? (maska |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1711 ? size_b |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1712 : (maskb ? size_a : MIN(size_a, size_b))) |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1713 : MAX(size_a, size_b); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1714 z = _PyLong_New(size_z); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1715 if (a == NULL || b == NULL || z == NULL) { |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1716 Py_XDECREF(a); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1717 Py_XDECREF(b); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1718 Py_XDECREF(z); |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1719 return NULL; |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1720 } |
|
dc6edfd4bae5
Two patches by Jason Harper:
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1721 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1722 for (i = 0; i < size_z; ++i) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1723 diga = (i < size_a ? a->ob_digit[i] : 0) ^ maska; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1724 digb = (i < size_b ? b->ob_digit[i] : 0) ^ maskb; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1725 switch (op) { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1726 case '&': z->ob_digit[i] = diga & digb; break; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1727 case '|': z->ob_digit[i] = diga | digb; break; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1728 case '^': z->ob_digit[i] = diga ^ digb; break; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1729 } |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1730 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1731 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1732 Py_DECREF(a); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1733 Py_DECREF(b); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1734 z = long_normalize(z); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1735 if (negz == 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1736 return (PyObject *) z; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1737 v = long_invert(z); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1738 Py_DECREF(z); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1739 return v; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1740 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1741 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1742 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1743 long_and(PyObject *v, PyObject *w) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1744 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1745 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1746 PyObject *c; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1747 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1748 c = long_bitwise(a, '&', b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1749 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1750 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1751 return c; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1752 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1753 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1754 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1755 long_xor(PyObject *v, PyObject *w) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1756 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1757 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1758 PyObject *c; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1759 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1760 c = long_bitwise(a, '^', b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1761 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1762 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1763 return c; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1764 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1765 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1766 static PyObject * |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1767 long_or(PyObject *v, PyObject *w) |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1768 { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1769 PyLongObject *a, *b; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1770 PyObject *c; |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1771 CONVERT_BINOP(v, w, &a, &b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1772 c = long_bitwise(a, '|', b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1773 Py_DECREF(a); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1774 Py_DECREF(b); |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1775 return c; |
| 242 | 1776 } |
| 1777 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1778 static int |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1779 long_coerce(PyObject **pv, PyObject **pw) |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1780 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1781 if (PyInt_Check(*pw)) { |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1782 *pw = PyLong_FromLong(PyInt_AS_LONG(*pw)); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1783 Py_INCREF(*pv); |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1784 return 0; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1785 } |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1786 return 1; /* Can't do it */ |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1787 } |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1788 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1789 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1790 long_int(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1791 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1792 long x; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1793 x = PyLong_AsLong(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1794 if (PyErr_Occurred()) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1795 return NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1796 return PyInt_FromLong(x); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1797 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1798 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1799 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1800 long_long(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1801 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1802 Py_INCREF(v); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1803 return v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1804 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1805 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1806 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1807 long_float(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1808 { |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4870
diff
changeset
|
1809 double result; |
|
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4870
diff
changeset
|
1810 PyFPE_START_PROTECT("long_float", return 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1811 result = PyLong_AsDouble(v); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5118
diff
changeset
|
1812 PyFPE_END_PROTECT(result) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1813 return PyFloat_FromDouble(result); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1814 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1815 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1816 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1817 long_oct(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1818 { |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
1819 return long_format(v, 8, 1); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1820 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1821 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1822 static PyObject * |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1823 long_hex(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1824 { |
|
11628
47f93a969366
long_format(): Now takes a third parameter, addL; iff true, a
Fred Drake <fdrake@acm.org>
parents:
11380
diff
changeset
|
1825 return long_format(v, 16, 1); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1826 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1827 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1828 static PyNumberMethods long_as_number = { |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1829 (binaryfunc) long_add, /*nb_add*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1830 (binaryfunc) long_sub, /*nb_subtract*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1831 (binaryfunc) long_mul, /*nb_multiply*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1832 (binaryfunc) long_div, /*nb_divide*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1833 (binaryfunc) long_mod, /*nb_remainder*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1834 (binaryfunc) long_divmod, /*nb_divmod*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1835 (ternaryfunc) long_pow, /*nb_power*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1836 (unaryfunc) long_neg, /*nb_negative*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1837 (unaryfunc) long_pos, /*tp_positive*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1838 (unaryfunc) long_abs, /*tp_absolute*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1839 (inquiry) long_nonzero, /*tp_nonzero*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1840 (unaryfunc) long_invert, /*nb_invert*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1841 (binaryfunc) long_lshift, /*nb_lshift*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1842 (binaryfunc) long_rshift, /*nb_rshift*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1843 (binaryfunc) long_and, /*nb_and*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1844 (binaryfunc) long_xor, /*nb_xor*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1845 (binaryfunc) long_or, /*nb_or*/ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13406
diff
changeset
|
1846 (coercion) long_coerce, /*nb_coerce*/ |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1847 (unaryfunc) long_int, /*nb_int*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1848 (unaryfunc) long_long, /*nb_long*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1849 (unaryfunc) long_float, /*nb_float*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1850 (unaryfunc) long_oct, /*nb_oct*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1851 (unaryfunc) long_hex, /*nb_hex*/ |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1852 0, /*nb_inplace_add*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1853 0, /*nb_inplace_subtract*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1854 0, /*nb_inplace_multiply*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1855 0, /*nb_inplace_divide*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1856 0, /*nb_inplace_remainder*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1857 0, /*nb_inplace_power*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1858 0, /*nb_inplace_lshift*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1859 0, /*nb_inplace_rshift*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1860 0, /*nb_inplace_and*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1861 0, /*nb_inplace_xor*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1862 0, /*nb_inplace_or*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1863 |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1864 /* New style slots */ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1865 (binaryfunc) long_cmp, /*nb_cmp*/ |
| 230 | 1866 }; |
| 1867 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1868 PyTypeObject PyLong_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1869 PyObject_HEAD_INIT(&PyType_Type) |
| 230 | 1870 0, |
| 1871 "long int", | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5288
diff
changeset
|
1872 sizeof(PyLongObject) - sizeof(digit), |
| 230 | 1873 sizeof(digit), |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1874 (destructor)long_dealloc, /*tp_dealloc*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1875 0, /*tp_print*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1876 0, /*tp_getattr*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1877 0, /*tp_setattr*/ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13406
diff
changeset
|
1878 (cmpfunc)long_compare, /*tp_compare*/ |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1879 (reprfunc)long_repr, /*tp_repr*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1880 &long_as_number, /*tp_as_number*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1881 0, /*tp_as_sequence*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1882 0, /*tp_as_mapping*/ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13406
diff
changeset
|
1883 (hashfunc)long_hash, /*tp_hash*/ |
|
13406
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1884 0, /*tp_call*/ |
|
a503af7e7fb7
Some cleanup of longs in prepartion for Cray J90 fixes: got
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
1885 (reprfunc)long_str, /*tp_str*/ |
|
15725
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1886 0, /*tp_getattro*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1887 0, /*tp_setattro*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1888 0, /*tp_as_buffer*/ |
|
8e402aeca0a3
Make long a new style number type. Sequence repeat is now done here
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
1889 Py_TPFLAGS_NEWSTYLENUMBER /*tp_flags*/ |
| 230 | 1890 }; |
