Mercurial > cpython-lru_cache-weakref
annotate Objects/longobject.c @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | 0510b948178e |
| children | 65d2d8e67da3 |
| rev | line source |
|---|---|
| 230 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
3 The Netherlands. |
| 230 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 25 /* Long (arbitrary precision) integer object implementation */ | |
| 26 | |
| 242 | 27 /* XXX The functional organization of this file is terrible */ |
| 28 | |
| 230 | 29 #include "allobjects.h" |
| 30 #include "longintrepr.h" | |
| 2482 | 31 #include "mymath.h" |
| 230 | 32 #include <assert.h> |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
33 #include <ctype.h> |
| 230 | 34 |
| 613 | 35 #define ABS(x) ((x) < 0 ? -(x) : (x)) |
| 36 | |
| 37 /* Forward */ | |
| 38 static longobject *long_normalize PROTO((longobject *)); | |
| 39 static longobject *mul1 PROTO((longobject *, wdigit)); | |
| 40 static longobject *muladd1 PROTO((longobject *, wdigit, wdigit)); | |
| 41 static longobject *divrem1 PROTO((longobject *, wdigit, digit *)); | |
|
1391
7c3245c18677
* ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
42 static object *long_format PROTO((object *aa, int base)); |
| 613 | 43 |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
44 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
|
45 |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
46 #define SIGCHECK(block) \ |
| 242 | 47 if (--ticker < 0) { \ |
| 48 ticker = 100; \ | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
49 if (sigcheck()) { block; } \ |
| 242 | 50 } |
| 51 | |
| 230 | 52 /* Normalize (remove leading zeros from) a long int object. |
| 53 Doesn't attempt to free the storage--in most cases, due to the nature | |
| 54 of the algorithms used, this could save at most be one word anyway. */ | |
| 55 | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
56 static longobject * |
| 230 | 57 long_normalize(v) |
| 58 register longobject *v; | |
| 59 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
60 int j = ABS(v->ob_size); |
| 230 | 61 register int i = j; |
| 62 | |
| 63 while (i > 0 && v->ob_digit[i-1] == 0) | |
| 64 --i; | |
| 65 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
|
66 v->ob_size = (v->ob_size < 0) ? -(i) : i; |
| 230 | 67 return v; |
| 68 } | |
| 69 | |
| 70 /* Allocate a new long int object with size digits. | |
| 71 Return NULL and set exception if we run out of memory. */ | |
| 72 | |
| 73 longobject * | |
| 74 alloclongobject(size) | |
| 75 int size; | |
| 76 { | |
| 77 return NEWVAROBJ(longobject, &Longtype, size); | |
| 78 } | |
| 79 | |
| 80 /* Create a new long int object from a C long int */ | |
| 81 | |
| 82 object * | |
| 83 newlongobject(ival) | |
| 84 long ival; | |
| 85 { | |
| 86 /* Assume a C long fits in at most 3 'digits' */ | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
87 /* XXX On 64 bit machines this isn't true!!! */ |
| 230 | 88 longobject *v = alloclongobject(3); |
| 89 if (v != NULL) { | |
| 90 if (ival < 0) { | |
| 91 ival = -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
|
92 v->ob_size = -(v->ob_size); |
| 230 | 93 } |
| 94 v->ob_digit[0] = ival & MASK; | |
| 95 v->ob_digit[1] = (ival >> SHIFT) & MASK; | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
96 v->ob_digit[2] = ((unsigned long)ival >> (2*SHIFT)) & MASK; |
| 230 | 97 v = long_normalize(v); |
| 98 } | |
| 99 return (object *)v; | |
| 100 } | |
| 101 | |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
102 /* 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
|
103 |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
104 object * |
| 2482 | 105 #ifdef MPW |
| 106 dnewlongobject(double dval) | |
| 107 #else | |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
108 dnewlongobject(dval) |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
109 double dval; |
| 2482 | 110 #endif /* MPW */ |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
111 { |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
112 longobject *v; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
113 double frac; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
114 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
|
115 neg = 0; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
116 if (dval < 0.0) { |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
117 neg = 1; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
118 dval = -dval; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
119 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
120 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
|
121 if (expo <= 0) |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
122 return newlongobject(0L); |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
123 ndig = (expo-1) / SHIFT + 1; /* Number of 'digits' in result */ |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
124 v = alloclongobject(ndig); |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
125 if (v == NULL) |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
126 return NULL; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
127 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
|
128 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
|
129 long bits = (long)frac; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
130 v->ob_digit[i] = bits; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
131 frac = frac - (double)bits; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
132 frac = ldexp(frac, SHIFT); |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
133 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
134 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
|
135 v->ob_size = -(v->ob_size); |
|
254
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
136 return (object *)v; |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
137 } |
|
71b0bd5ed162
Added dnewlongobject(), function to convert double to long int.
Guido van Rossum <guido@python.org>
parents:
250
diff
changeset
|
138 |
| 230 | 139 /* Get a C long int from a long int object. |
| 140 Returns -1 and sets an error condition if overflow occurs. */ | |
| 141 | |
| 142 long | |
| 143 getlongvalue(vv) | |
| 144 object *vv; | |
| 145 { | |
| 146 register longobject *v; | |
| 147 long x, prev; | |
| 148 int i, sign; | |
| 149 | |
| 150 if (vv == NULL || !is_longobject(vv)) { | |
| 151 err_badcall(); | |
| 152 return -1; | |
| 153 } | |
| 154 v = (longobject *)vv; | |
| 155 i = v->ob_size; | |
| 156 sign = 1; | |
| 157 x = 0; | |
| 158 if (i < 0) { | |
| 159 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
|
160 i = -(i); |
| 230 | 161 } |
| 162 while (--i >= 0) { | |
| 163 prev = x; | |
| 164 x = (x << SHIFT) + v->ob_digit[i]; | |
| 165 if ((x >> SHIFT) != prev) { | |
|
1908
0437738279a8
* Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents:
1837
diff
changeset
|
166 err_setstr(OverflowError, |
| 230 | 167 "long int too long to convert"); |
| 168 return -1; | |
| 169 } | |
| 170 } | |
| 171 return x * sign; | |
| 172 } | |
| 173 | |
| 174 /* Get a C double from a long int object. No overflow check. */ | |
| 175 | |
| 176 double | |
| 177 dgetlongvalue(vv) | |
| 178 object *vv; | |
| 179 { | |
| 180 register longobject *v; | |
| 181 double x; | |
| 182 double multiplier = (double) (1L << SHIFT); | |
| 183 int i, sign; | |
| 184 | |
| 185 if (vv == NULL || !is_longobject(vv)) { | |
| 186 err_badcall(); | |
| 187 return -1; | |
| 188 } | |
| 189 v = (longobject *)vv; | |
| 190 i = v->ob_size; | |
| 191 sign = 1; | |
| 192 x = 0.0; | |
| 193 if (i < 0) { | |
| 194 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
|
195 i = -(i); |
| 230 | 196 } |
| 197 while (--i >= 0) { | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
198 x = x*multiplier + (double)v->ob_digit[i]; |
| 230 | 199 } |
| 200 return x * sign; | |
| 201 } | |
| 202 | |
| 203 /* Multiply by a single digit, ignoring the sign. */ | |
| 204 | |
| 613 | 205 static longobject * |
| 230 | 206 mul1(a, n) |
| 207 longobject *a; | |
| 242 | 208 wdigit n; |
| 230 | 209 { |
| 210 return muladd1(a, n, (digit)0); | |
| 211 } | |
| 212 | |
| 213 /* Multiply by a single digit and add a single digit, ignoring the sign. */ | |
| 214 | |
| 613 | 215 static longobject * |
| 230 | 216 muladd1(a, n, extra) |
| 217 longobject *a; | |
| 242 | 218 wdigit n; |
| 219 wdigit extra; | |
| 230 | 220 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
221 int size_a = ABS(a->ob_size); |
| 230 | 222 longobject *z = alloclongobject(size_a+1); |
| 223 twodigits carry = extra; | |
| 224 int i; | |
| 225 | |
| 226 if (z == NULL) | |
| 227 return NULL; | |
| 228 for (i = 0; i < size_a; ++i) { | |
| 229 carry += (twodigits)a->ob_digit[i] * n; | |
| 230 z->ob_digit[i] = carry & MASK; | |
| 231 carry >>= SHIFT; | |
| 232 } | |
| 233 z->ob_digit[i] = carry; | |
| 234 return long_normalize(z); | |
| 235 } | |
| 236 | |
| 237 /* Divide a long integer by a digit, returning both the quotient | |
| 238 (as function result) and the remainder (through *prem). | |
| 239 The sign of a is ignored; n should not be zero. */ | |
| 240 | |
| 613 | 241 static longobject * |
| 230 | 242 divrem1(a, n, prem) |
| 243 longobject *a; | |
| 242 | 244 wdigit n; |
| 230 | 245 digit *prem; |
| 246 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
247 int size = ABS(a->ob_size); |
| 230 | 248 longobject *z; |
| 249 int i; | |
| 250 twodigits rem = 0; | |
| 251 | |
| 252 assert(n > 0 && n <= MASK); | |
| 253 z = alloclongobject(size); | |
| 254 if (z == NULL) | |
| 255 return NULL; | |
| 256 for (i = size; --i >= 0; ) { | |
| 257 rem = (rem << SHIFT) + a->ob_digit[i]; | |
| 258 z->ob_digit[i] = rem/n; | |
| 259 rem %= n; | |
| 260 } | |
| 261 *prem = rem; | |
| 262 return long_normalize(z); | |
| 263 } | |
| 264 | |
| 265 /* 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
|
266 Return a string object. |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
267 If base is 8 or 16, add the proper prefix '0' or '0x'. |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
268 External linkage: used in bltinmodule.c by hex() and oct(). */ |
| 230 | 269 |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
270 static object * |
| 613 | 271 long_format(aa, base) |
| 272 object *aa; | |
| 230 | 273 int base; |
| 274 { | |
| 613 | 275 register longobject *a = (longobject *)aa; |
| 230 | 276 stringobject *str; |
| 277 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
|
278 int size_a = ABS(a->ob_size); |
| 230 | 279 char *p; |
| 280 int bits; | |
| 281 char sign = '\0'; | |
| 613 | 282 |
| 283 if (a == NULL || !is_longobject(a)) { | |
| 284 err_badcall(); | |
| 285 return NULL; | |
| 286 } | |
| 230 | 287 assert(base >= 2 && base <= 36); |
| 288 | |
| 289 /* Compute a rough upper bound for the length of the string */ | |
| 290 i = base; | |
| 291 bits = 0; | |
| 292 while (i > 1) { | |
| 293 ++bits; | |
| 294 i >>= 1; | |
| 295 } | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
296 i = 6 + (size_a*SHIFT + bits-1) / bits; |
| 230 | 297 str = (stringobject *) newsizedstringobject((char *)0, i); |
| 298 if (str == NULL) | |
| 299 return NULL; | |
| 300 p = GETSTRINGVALUE(str) + i; | |
| 301 *p = '\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
|
302 *--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
|
303 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
|
304 sign = '-'; |
| 230 | 305 |
| 306 INCREF(a); | |
| 307 do { | |
| 308 digit rem; | |
| 309 longobject *temp = divrem1(a, (digit)base, &rem); | |
| 310 if (temp == NULL) { | |
| 311 DECREF(a); | |
| 312 DECREF(str); | |
| 313 return NULL; | |
| 314 } | |
| 315 if (rem < 10) | |
| 316 rem += '0'; | |
| 317 else | |
| 318 rem += 'A'-10; | |
| 319 assert(p > GETSTRINGVALUE(str)); | |
| 320 *--p = rem; | |
| 321 DECREF(a); | |
| 322 a = temp; | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
323 SIGCHECK({ |
| 230 | 324 DECREF(a); |
| 325 DECREF(str); | |
| 326 return NULL; | |
| 242 | 327 }) |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
328 } while (ABS(a->ob_size) != 0); |
| 230 | 329 DECREF(a); |
|
958
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
330 if (base == 8) { |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
331 if (size_a != 0) |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
332 *--p = '0'; |
|
a736ef1840a5
oct(0) should return '0', not '00'
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
333 } |
|
406
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
334 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
|
335 *--p = 'x'; |
|
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
336 *--p = '0'; |
|
e628d09ce22f
Changed convert to add '0' or '0x' prefix for oct/hex.
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
337 } |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
338 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
|
339 *--p = '#'; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
340 *--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
|
341 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
|
342 *--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
|
343 } |
| 230 | 344 if (sign) |
| 345 *--p = sign; | |
| 346 if (p != GETSTRINGVALUE(str)) { | |
| 347 char *q = GETSTRINGVALUE(str); | |
| 348 assert(p > q); | |
| 349 do { | |
| 350 } while ((*q++ = *p++) != '\0'); | |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
351 q--; |
| 230 | 352 resizestring((object **)&str, (int) (q - GETSTRINGVALUE(str))); |
| 353 } | |
| 613 | 354 return (object *)str; |
| 230 | 355 } |
| 356 | |
|
2158
29720c5d9e7e
long_scan is no longer used
Guido van Rossum <guido@python.org>
parents:
2111
diff
changeset
|
357 #if 0 |
| 230 | 358 /* Convert a string to a long int object, in a given base. |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
359 Base zero implies a default depending on the number. |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
360 External linkage: used in compile.c and stropmodule.c. */ |
| 230 | 361 |
| 362 object * | |
| 363 long_scan(str, base) | |
| 364 char *str; | |
| 365 int base; | |
| 366 { | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
367 return long_escan(str, (char **)NULL, base); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
368 } |
|
2158
29720c5d9e7e
long_scan is no longer used
Guido van Rossum <guido@python.org>
parents:
2111
diff
changeset
|
369 #endif |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
370 |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
371 object * |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
372 long_escan(str, pend, base) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
373 char *str; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
374 char **pend; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
375 int base; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
376 { |
| 230 | 377 int sign = 1; |
| 378 longobject *z; | |
| 379 | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
380 if (base != 0 && base < 2 || base > 36) { |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
381 err_setstr(ValueError, "invalid base for long literal"); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
382 return NULL; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
383 } |
|
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
|
384 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
|
385 str++; |
| 230 | 386 if (*str == '+') |
| 387 ++str; | |
| 388 else if (*str == '-') { | |
| 389 ++str; | |
| 390 sign = -1; | |
| 391 } | |
|
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
|
392 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
|
393 str++; |
| 230 | 394 if (base == 0) { |
| 395 if (str[0] != '0') | |
| 396 base = 10; | |
| 397 else if (str[1] == 'x' || str[1] == 'X') | |
| 398 base = 16; | |
| 399 else | |
| 400 base = 8; | |
| 401 } | |
| 402 if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) | |
| 403 str += 2; | |
| 404 z = alloclongobject(0); | |
| 405 for ( ; z != NULL; ++str) { | |
| 406 int k = -1; | |
| 407 longobject *temp; | |
| 408 | |
| 409 if (*str <= '9') | |
| 410 k = *str - '0'; | |
| 411 else if (*str >= 'a') | |
| 412 k = *str - 'a' + 10; | |
| 413 else if (*str >= 'A') | |
| 414 k = *str - 'A' + 10; | |
| 415 if (k < 0 || k >= base) | |
| 416 break; | |
| 417 temp = muladd1(z, (digit)base, (digit)k); | |
| 418 DECREF(z); | |
| 419 z = temp; | |
| 420 } | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
421 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
|
422 z->ob_size = -(z->ob_size); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
423 if (pend) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
424 *pend = str; |
| 230 | 425 return (object *) z; |
| 426 } | |
| 427 | |
| 428 static longobject *x_divrem PROTO((longobject *, longobject *, longobject **)); | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
429 static object *long_pos PROTO((longobject *)); |
| 613 | 430 static long_divrem PROTO((longobject *, longobject *, |
| 431 longobject **, longobject **)); | |
| 230 | 432 |
| 433 /* Long division with remainder, top-level routine */ | |
| 434 | |
| 613 | 435 static int |
| 436 long_divrem(a, b, pdiv, prem) | |
| 230 | 437 longobject *a, *b; |
| 613 | 438 longobject **pdiv; |
| 230 | 439 longobject **prem; |
| 440 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
441 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
| 230 | 442 longobject *z; |
| 443 | |
| 444 if (size_b == 0) { | |
| 613 | 445 err_setstr(ZeroDivisionError, "long division or modulo"); |
| 446 return -1; | |
| 230 | 447 } |
| 448 if (size_a < size_b || | |
| 242 | 449 size_a == size_b && |
| 450 a->ob_digit[size_a-1] < b->ob_digit[size_b-1]) { | |
| 230 | 451 /* |a| < |b|. */ |
| 613 | 452 *pdiv = alloclongobject(0); |
| 453 INCREF(a); | |
| 454 *prem = (longobject *) a; | |
| 455 return 0; | |
| 230 | 456 } |
| 457 if (size_b == 1) { | |
| 458 digit rem = 0; | |
| 459 z = divrem1(a, b->ob_digit[0], &rem); | |
| 613 | 460 if (z == NULL) |
| 461 return -1; | |
| 462 *prem = (longobject *) newlongobject((long)rem); | |
| 230 | 463 } |
| 613 | 464 else { |
| 230 | 465 z = x_divrem(a, b, prem); |
| 613 | 466 if (z == NULL) |
| 467 return -1; | |
| 468 } | |
| 230 | 469 /* Set the signs. |
| 470 The quotient z has the sign of a*b; | |
| 471 the remainder r has the sign of a, | |
| 472 so a = b*z + r. */ | |
| 613 | 473 if ((a->ob_size < 0) != (b->ob_size < 0)) |
| 474 z->ob_size = -(z->ob_size); | |
| 475 if (a->ob_size < 0 && (*prem)->ob_size != 0) | |
| 476 (*prem)->ob_size = -((*prem)->ob_size); | |
| 477 *pdiv = z; | |
| 478 return 0; | |
| 230 | 479 } |
| 480 | |
| 242 | 481 /* Unsigned long division with remainder -- the algorithm */ |
| 230 | 482 |
| 483 static longobject * | |
| 484 x_divrem(v1, w1, prem) | |
| 485 longobject *v1, *w1; | |
| 486 longobject **prem; | |
| 487 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
488 int size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size); |
| 230 | 489 digit d = (twodigits)BASE / (w1->ob_digit[size_w-1] + 1); |
| 490 longobject *v = mul1(v1, d); | |
| 491 longobject *w = mul1(w1, d); | |
| 492 longobject *a; | |
| 493 int j, k; | |
| 494 | |
| 495 if (v == NULL || w == NULL) { | |
| 496 XDECREF(v); | |
| 497 XDECREF(w); | |
| 498 return NULL; | |
| 499 } | |
| 500 | |
| 501 assert(size_v >= size_w && size_w > 1); /* Assert checks by div() */ | |
| 242 | 502 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
|
503 assert(size_w == ABS(w->ob_size)); /* That's how d was calculated */ |
| 230 | 504 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
505 size_v = ABS(v->ob_size); |
| 230 | 506 a = alloclongobject(size_v - size_w + 1); |
| 507 | |
| 508 for (j = size_v, k = a->ob_size-1; a != NULL && k >= 0; --j, --k) { | |
| 509 digit vj = (j >= size_v) ? 0 : v->ob_digit[j]; | |
| 510 twodigits q; | |
| 242 | 511 stwodigits carry = 0; |
| 230 | 512 int i; |
| 513 | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
514 SIGCHECK({ |
| 230 | 515 DECREF(a); |
| 516 a = NULL; | |
| 517 break; | |
| 242 | 518 }) |
| 230 | 519 if (vj == w->ob_digit[size_w-1]) |
| 520 q = MASK; | |
| 521 else | |
| 522 q = (((twodigits)vj << SHIFT) + v->ob_digit[j-1]) / | |
| 523 w->ob_digit[size_w-1]; | |
| 524 | |
| 525 while (w->ob_digit[size_w-2]*q > | |
| 526 (( | |
| 527 ((twodigits)vj << SHIFT) | |
| 528 + v->ob_digit[j-1] | |
| 529 - q*w->ob_digit[size_w-1] | |
| 530 ) << SHIFT) | |
| 531 + v->ob_digit[j-2]) | |
| 532 --q; | |
| 533 | |
| 534 for (i = 0; i < size_w && i+k < size_v; ++i) { | |
| 535 twodigits z = w->ob_digit[i] * q; | |
| 536 digit zz = z >> SHIFT; | |
| 537 carry += v->ob_digit[i+k] - z + ((twodigits)zz << SHIFT); | |
| 538 v->ob_digit[i+k] = carry & MASK; | |
| 539 carry = (carry >> SHIFT) - zz; | |
| 540 } | |
| 541 | |
| 542 if (i+k < size_v) { | |
| 543 carry += v->ob_digit[i+k]; | |
| 544 v->ob_digit[i+k] = 0; | |
| 545 } | |
| 546 | |
| 547 if (carry == 0) | |
| 548 a->ob_digit[k] = q; | |
| 549 else { | |
| 550 assert(carry == -1); | |
| 551 a->ob_digit[k] = q-1; | |
| 552 carry = 0; | |
| 553 for (i = 0; i < size_w && i+k < size_v; ++i) { | |
| 554 carry += v->ob_digit[i+k] + w->ob_digit[i]; | |
| 555 v->ob_digit[i+k] = carry & MASK; | |
| 556 carry >>= SHIFT; | |
| 557 } | |
| 558 } | |
| 559 } /* for j, k */ | |
| 560 | |
|
2111
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
561 if (a == NULL) |
|
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
562 *prem = NULL; |
|
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
563 else { |
| 230 | 564 a = long_normalize(a); |
| 613 | 565 *prem = divrem1(v, d, &d); |
| 566 /* d receives the (unused) remainder */ | |
| 567 if (*prem == NULL) { | |
| 568 DECREF(a); | |
| 569 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
|
570 } |
| 230 | 571 } |
| 572 DECREF(v); | |
| 573 DECREF(w); | |
| 574 return a; | |
| 575 } | |
| 576 | |
| 577 /* Methods */ | |
| 578 | |
| 613 | 579 /* Forward */ |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
580 static void long_dealloc PROTO((object *)); |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
581 static object *long_repr PROTO((object *)); |
| 613 | 582 static int long_compare PROTO((longobject *, longobject *)); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
583 static long long_hash PROTO((longobject *)); |
| 613 | 584 |
| 585 static object *long_add PROTO((longobject *, longobject *)); | |
| 586 static object *long_sub PROTO((longobject *, longobject *)); | |
| 587 static object *long_mul PROTO((longobject *, longobject *)); | |
| 588 static object *long_div PROTO((longobject *, longobject *)); | |
| 589 static object *long_mod PROTO((longobject *, longobject *)); | |
| 590 static object *long_divmod PROTO((longobject *, longobject *)); | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
591 static object *long_pow PROTO((longobject *, longobject *, longobject *)); |
| 613 | 592 static object *long_neg PROTO((longobject *)); |
| 593 static object *long_pos PROTO((longobject *)); | |
| 594 static object *long_abs PROTO((longobject *)); | |
| 595 static int long_nonzero PROTO((longobject *)); | |
| 596 static object *long_invert PROTO((longobject *)); | |
| 597 static object *long_lshift PROTO((longobject *, longobject *)); | |
| 598 static object *long_rshift PROTO((longobject *, longobject *)); | |
| 599 static object *long_and PROTO((longobject *, longobject *)); | |
| 600 static object *long_xor PROTO((longobject *, longobject *)); | |
| 601 static object *long_or PROTO((longobject *, longobject *)); | |
| 602 | |
| 230 | 603 static void |
| 604 long_dealloc(v) | |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
605 object *v; |
| 230 | 606 { |
| 607 DEL(v); | |
| 608 } | |
| 609 | |
| 610 static object * | |
| 611 long_repr(v) | |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
612 object *v; |
| 230 | 613 { |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
614 return long_format(v, 10); |
| 230 | 615 } |
| 616 | |
| 617 static int | |
| 618 long_compare(a, b) | |
| 619 longobject *a, *b; | |
| 620 { | |
| 621 int sign; | |
| 622 | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
623 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
|
624 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
|
625 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
|
626 else |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
627 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
|
628 } |
| 230 | 629 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
|
630 int i = ABS(a->ob_size); |
| 230 | 631 while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i]) |
| 632 ; | |
| 633 if (i < 0) | |
| 634 sign = 0; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
635 else { |
| 230 | 636 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
|
637 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
|
638 sign = -sign; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
639 } |
| 230 | 640 } |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
641 return sign < 0 ? -1 : sign > 0 ? 1 : 0; |
| 230 | 642 } |
| 643 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
644 static long |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
645 long_hash(v) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
646 longobject *v; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
647 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
648 long x; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
649 int i, sign; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
650 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
651 /* 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
|
652 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
|
653 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
|
654 i = v->ob_size; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
655 sign = 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
656 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
657 if (i < 0) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
658 sign = -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
659 i = -(i); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
660 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
661 while (--i >= 0) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
662 /* Force a 32-bit circular shift */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
663 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
|
664 x += v->ob_digit[i]; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
665 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
666 x = x * sign; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
667 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
668 x = -2; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
669 return x; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
670 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
671 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
672 |
| 230 | 673 /* Add the absolute values of two long integers. */ |
| 674 | |
| 675 static longobject *x_add PROTO((longobject *, longobject *)); | |
| 676 static longobject * | |
| 677 x_add(a, b) | |
| 678 longobject *a, *b; | |
| 679 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
680 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
| 230 | 681 longobject *z; |
| 682 int i; | |
| 683 digit carry = 0; | |
| 684 | |
| 685 /* Ensure a is the larger of the two: */ | |
| 686 if (size_a < size_b) { | |
| 687 { longobject *temp = a; a = b; b = temp; } | |
| 688 { int size_temp = size_a; size_a = size_b; size_b = size_temp; } | |
| 689 } | |
| 690 z = alloclongobject(size_a+1); | |
| 691 if (z == NULL) | |
| 692 return NULL; | |
| 693 for (i = 0; i < size_b; ++i) { | |
| 694 carry += a->ob_digit[i] + b->ob_digit[i]; | |
| 695 z->ob_digit[i] = carry & MASK; | |
| 696 /* The following assumes unsigned shifts don't | |
| 697 propagate the sign bit. */ | |
| 698 carry >>= SHIFT; | |
| 699 } | |
| 700 for (; i < size_a; ++i) { | |
| 701 carry += a->ob_digit[i]; | |
| 702 z->ob_digit[i] = carry & MASK; | |
| 703 carry >>= SHIFT; | |
| 704 } | |
| 705 z->ob_digit[i] = carry; | |
| 706 return long_normalize(z); | |
| 707 } | |
| 708 | |
| 709 /* Subtract the absolute values of two integers. */ | |
| 710 | |
| 711 static longobject *x_sub PROTO((longobject *, longobject *)); | |
| 712 static longobject * | |
| 713 x_sub(a, b) | |
| 714 longobject *a, *b; | |
| 715 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
716 int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); |
| 230 | 717 longobject *z; |
| 718 int i; | |
| 719 int sign = 1; | |
| 720 digit borrow = 0; | |
| 721 | |
| 722 /* Ensure a is the larger of the two: */ | |
| 723 if (size_a < size_b) { | |
| 724 sign = -1; | |
| 725 { longobject *temp = a; a = b; b = temp; } | |
| 726 { int size_temp = size_a; size_a = size_b; size_b = size_temp; } | |
| 727 } | |
| 728 else if (size_a == size_b) { | |
| 729 /* Find highest digit where a and b differ: */ | |
| 730 i = size_a; | |
| 731 while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i]) | |
| 732 ; | |
| 733 if (i < 0) | |
| 734 return alloclongobject(0); | |
| 735 if (a->ob_digit[i] < b->ob_digit[i]) { | |
| 736 sign = -1; | |
| 737 { longobject *temp = a; a = b; b = temp; } | |
| 738 } | |
| 739 size_a = size_b = i+1; | |
| 740 } | |
| 741 z = alloclongobject(size_a); | |
| 742 if (z == NULL) | |
| 743 return NULL; | |
| 744 for (i = 0; i < size_b; ++i) { | |
| 745 /* The following assumes unsigned arithmetic | |
| 746 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
|
747 borrow = a->ob_digit[i] - b->ob_digit[i] - borrow; |
| 230 | 748 z->ob_digit[i] = borrow & MASK; |
| 749 borrow >>= SHIFT; | |
| 750 borrow &= 1; /* Keep only one sign bit */ | |
| 751 } | |
| 752 for (; i < size_a; ++i) { | |
| 753 borrow = a->ob_digit[i] - borrow; | |
| 754 z->ob_digit[i] = borrow & MASK; | |
| 755 borrow >>= SHIFT; | |
| 756 } | |
| 757 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
|
758 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
|
759 z->ob_size = -(z->ob_size); |
| 230 | 760 return long_normalize(z); |
| 761 } | |
| 762 | |
| 763 static object * | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
764 long_add(a, b) |
| 230 | 765 longobject *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
|
766 longobject *b; |
| 230 | 767 { |
| 768 longobject *z; | |
| 769 | |
| 770 if (a->ob_size < 0) { | |
| 771 if (b->ob_size < 0) { | |
| 772 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
|
773 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
|
774 z->ob_size = -(z->ob_size); |
| 230 | 775 } |
| 776 else | |
| 777 z = x_sub(b, a); | |
| 778 } | |
| 779 else { | |
| 780 if (b->ob_size < 0) | |
| 781 z = x_sub(a, b); | |
| 782 else | |
| 783 z = x_add(a, b); | |
| 784 } | |
| 785 return (object *)z; | |
| 786 } | |
| 787 | |
| 788 static object * | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
789 long_sub(a, b) |
| 230 | 790 longobject *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
|
791 longobject *b; |
| 230 | 792 { |
| 793 longobject *z; | |
| 794 | |
| 795 if (a->ob_size < 0) { | |
| 796 if (b->ob_size < 0) | |
| 797 z = x_sub(a, b); | |
| 798 else | |
| 799 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
|
800 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
|
801 z->ob_size = -(z->ob_size); |
| 230 | 802 } |
| 803 else { | |
| 804 if (b->ob_size < 0) | |
| 805 z = x_add(a, b); | |
| 806 else | |
| 807 z = x_sub(a, b); | |
| 808 } | |
| 809 return (object *)z; | |
| 810 } | |
| 811 | |
| 812 static object * | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
813 long_mul(a, b) |
| 230 | 814 longobject *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
|
815 longobject *b; |
| 230 | 816 { |
| 817 int size_a; | |
| 818 int size_b; | |
| 819 longobject *z; | |
| 820 int i; | |
| 821 | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
822 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
|
823 size_b = ABS(b->ob_size); |
| 230 | 824 z = alloclongobject(size_a + size_b); |
| 825 if (z == NULL) | |
| 826 return NULL; | |
| 827 for (i = 0; i < z->ob_size; ++i) | |
| 828 z->ob_digit[i] = 0; | |
| 829 for (i = 0; i < size_a; ++i) { | |
| 830 twodigits carry = 0; | |
| 831 twodigits f = a->ob_digit[i]; | |
| 832 int j; | |
| 833 | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
834 SIGCHECK({ |
| 230 | 835 DECREF(z); |
| 836 return NULL; | |
| 242 | 837 }) |
| 230 | 838 for (j = 0; j < size_b; ++j) { |
| 839 carry += z->ob_digit[i+j] + b->ob_digit[j] * f; | |
| 840 z->ob_digit[i+j] = carry & MASK; | |
| 841 carry >>= SHIFT; | |
| 842 } | |
| 843 for (; carry != 0; ++j) { | |
| 844 assert(i+j < z->ob_size); | |
| 845 carry += z->ob_digit[i+j]; | |
| 846 z->ob_digit[i+j] = carry & MASK; | |
| 847 carry >>= SHIFT; | |
| 848 } | |
| 849 } | |
| 850 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
|
851 z->ob_size = -(z->ob_size); |
| 230 | 852 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
|
853 z->ob_size = -(z->ob_size); |
| 230 | 854 return (object *) long_normalize(z); |
| 855 } | |
| 856 | |
| 613 | 857 /* The / and % operators are now defined in terms of divmod(). |
| 858 The expression a mod b has the value a - b*floor(a/b). | |
| 859 The long_divrem function gives the remainder after division of | |
| 230 | 860 |a| by |b|, with the sign of a. This is also expressed |
| 861 as a - b*trunc(a/b), if trunc truncates towards zero. | |
| 862 Some examples: | |
| 863 a b a rem b a mod b | |
| 864 13 10 3 3 | |
| 865 -13 10 -3 7 | |
| 866 13 -10 3 -7 | |
| 867 -13 -10 -3 -3 | |
| 868 So, to get from rem to mod, we have to add b if a and b | |
| 242 | 869 have different signs. We then subtract one from the 'div' |
| 870 part of the outcome to keep the invariant intact. */ | |
| 230 | 871 |
| 613 | 872 static int l_divmod PROTO((longobject *, longobject *, |
| 873 longobject **, longobject **)); | |
| 874 static int | |
| 875 l_divmod(v, w, pdiv, pmod) | |
| 876 longobject *v; | |
| 877 longobject *w; | |
| 878 longobject **pdiv; | |
| 879 longobject **pmod; | |
| 880 { | |
| 881 longobject *div, *mod; | |
| 882 | |
| 883 if (long_divrem(v, w, &div, &mod) < 0) | |
| 884 return -1; | |
| 885 if (mod->ob_size < 0 && w->ob_size > 0 || | |
| 886 mod->ob_size > 0 && w->ob_size < 0) { | |
| 887 longobject *temp; | |
| 888 longobject *one; | |
| 889 temp = (longobject *) long_add(mod, w); | |
| 890 DECREF(mod); | |
| 891 mod = temp; | |
| 892 if (mod == NULL) { | |
| 893 DECREF(div); | |
| 894 return -1; | |
| 895 } | |
| 896 one = (longobject *) newlongobject(1L); | |
| 897 if (one == NULL || | |
| 898 (temp = (longobject *) long_sub(div, one)) == NULL) { | |
| 899 DECREF(mod); | |
| 900 DECREF(div); | |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
901 XDECREF(one); |
| 613 | 902 return -1; |
| 903 } | |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
904 DECREF(one); |
| 613 | 905 DECREF(div); |
| 906 div = temp; | |
| 907 } | |
| 908 *pdiv = div; | |
| 909 *pmod = mod; | |
| 910 return 0; | |
| 911 } | |
| 912 | |
| 913 static object * | |
| 914 long_div(v, w) | |
| 915 longobject *v; | |
| 916 longobject *w; | |
| 917 { | |
| 918 longobject *div, *mod; | |
| 919 if (l_divmod(v, w, &div, &mod) < 0) | |
| 920 return NULL; | |
| 921 DECREF(mod); | |
| 922 return (object *)div; | |
| 923 } | |
| 924 | |
| 925 static object * | |
| 926 long_mod(v, w) | |
| 927 longobject *v; | |
| 928 longobject *w; | |
| 929 { | |
| 930 longobject *div, *mod; | |
| 931 if (l_divmod(v, w, &div, &mod) < 0) | |
| 932 return NULL; | |
| 933 DECREF(div); | |
| 934 return (object *)mod; | |
| 935 } | |
| 936 | |
| 230 | 937 static object * |
| 938 long_divmod(v, w) | |
| 939 longobject *v; | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
940 longobject *w; |
| 230 | 941 { |
| 942 object *z; | |
| 613 | 943 longobject *div, *mod; |
| 944 if (l_divmod(v, w, &div, &mod) < 0) | |
| 230 | 945 return NULL; |
| 946 z = newtupleobject(2); | |
| 947 if (z != NULL) { | |
| 948 settupleitem(z, 0, (object *) div); | |
| 613 | 949 settupleitem(z, 1, (object *) mod); |
| 230 | 950 } |
| 951 else { | |
| 952 DECREF(div); | |
| 613 | 953 DECREF(mod); |
| 230 | 954 } |
| 955 return z; | |
| 956 } | |
| 957 | |
| 958 static object * | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
959 long_pow(a, b, c) |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
960 longobject *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
|
961 longobject *b; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
962 longobject *c; |
| 230 | 963 { |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
964 longobject *z, *div, *mod; |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
965 int size_b, i; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
966 |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
967 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
|
968 if (size_b < 0) { |
| 475 | 969 err_setstr(ValueError, "long integer to the negative power"); |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
970 return NULL; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
971 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
972 z = (longobject *)newlongobject(1L); |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
973 INCREF(a); |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
974 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
|
975 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
|
976 int j; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
977 |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
978 for (j = 0; j < SHIFT; ++j) { |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
979 longobject *temp; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
980 |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
981 if (bi & 1) { |
| 613 | 982 temp = (longobject *)long_mul(z, a); |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
983 DECREF(z); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
984 if ((object*)c!=None && temp!=NULL) { |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
985 l_divmod(temp, c, &div, &mod); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
986 XDECREF(div); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
987 DECREF(temp); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
988 temp = mod; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
989 } |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
990 z = temp; |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
991 if (z == NULL) |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
992 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
993 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
994 bi >>= 1; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
995 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
|
996 break; |
| 613 | 997 temp = (longobject *)long_mul(a, a); |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
998 DECREF(a); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
999 if ((object*)c!=None && temp!=NULL) { |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1000 l_divmod(temp, c, &div, &mod); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1001 XDECREF(div); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1002 DECREF(temp); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1003 temp = mod; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1004 } |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1005 a = temp; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1006 if (a == NULL) { |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1007 DECREF(z); |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1008 z = NULL; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1009 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1010 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1011 } |
|
2111
30cbe024df40
fix memory leak and null pointer dereference
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
1012 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
|
1013 break; |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1014 } |
|
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1015 XDECREF(a); |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1016 if ((object*)c!=None && z!=NULL) { |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1017 l_divmod(z, c, &div, &mod); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1018 XDECREF(div); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1019 DECREF(z); |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1020 z=mod; |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1021 } |
|
250
b9986009d7dc
Fix off-by-one error in long_repr.
Guido van Rossum <guido@python.org>
parents:
242
diff
changeset
|
1022 return (object *)z; |
| 230 | 1023 } |
| 1024 | |
| 1025 static object * | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1026 long_invert(v) |
| 230 | 1027 longobject *v; |
| 1028 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1029 /* Implement ~x as -(x+1) */ |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1030 longobject *x; |
| 613 | 1031 longobject *w; |
| 1032 w = (longobject *)newlongobject(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
|
1033 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
|
1034 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
|
1035 x = (longobject *) long_add(v, w); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1036 DECREF(w); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1037 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
|
1038 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
|
1039 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
|
1040 x->ob_size = -(x->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
|
1041 return (object *)x; |
| 230 | 1042 } |
| 1043 | |
| 1044 static object * | |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1045 long_pos(v) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1046 longobject *v; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1047 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1048 INCREF(v); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1049 return (object *)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
|
1050 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1051 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1052 static object * |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1053 long_neg(v) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1054 longobject *v; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1055 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1056 longobject *z; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1057 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
|
1058 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
|
1059 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
|
1060 /* -0 == 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
|
1061 INCREF(v); |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1062 return (object *) 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
|
1063 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1064 z = alloclongobject(ABS(n)); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 z->ob_size = -(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
|
1070 return (object *)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
|
1071 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1072 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1073 static object * |
| 230 | 1074 long_abs(v) |
| 1075 longobject *v; | |
| 1076 { | |
| 1077 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
|
1078 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
|
1079 else { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1080 INCREF(v); |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1081 return (object *)v; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1082 } |
| 230 | 1083 } |
| 1084 | |
| 242 | 1085 static int |
| 1086 long_nonzero(v) | |
| 1087 longobject *v; | |
| 1088 { | |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1089 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
|
1090 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1091 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1092 static object * |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1093 long_rshift(a, b) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1094 longobject *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
|
1095 longobject *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
|
1096 { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1097 longobject *z; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1098 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
|
1099 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
|
1100 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
|
1101 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1102 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
|
1103 /* Right shifting negative numbers is harder */ |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1104 longobject *a1, *a2, *a3; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1105 a1 = (longobject *) long_invert(a); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1106 if (a1 == NULL) 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
|
1107 a2 = (longobject *) long_rshift(a1, b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1108 DECREF(a1); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1109 if (a2 == NULL) 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
|
1110 a3 = (longobject *) long_invert(a2); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1111 DECREF(a2); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1112 return (object *) a3; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1113 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1114 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1115 shiftby = getlongvalue((object *)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
|
1116 if (shiftby == -1L && err_occurred()) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1117 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1118 if (shiftby < 0) { |
| 475 | 1119 err_setstr(ValueError, "negative shift count"); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1120 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1121 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1122 wordshift = shiftby / SHIFT; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1123 newsize = ABS(a->ob_size) - wordshift; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1124 if (newsize <= 0) { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1125 z = alloclongobject(0); |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1126 return (object *)z; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1127 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1128 loshift = shiftby % SHIFT; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1129 hishift = SHIFT - loshift; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1130 lomask = ((digit)1 << hishift) - 1; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1131 himask = MASK ^ lomask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1132 z = alloclongobject(newsize); |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1133 if (z == NULL) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1134 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1135 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
|
1136 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
|
1137 for (i = 0, j = wordshift; i < newsize; 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
|
1138 z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1139 if (i+1 < newsize) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1140 z->ob_digit[i] |= |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1141 (a->ob_digit[j+1] << hishift) & himask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1142 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1143 return (object *) 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
|
1144 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1145 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1146 static object * |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1147 long_lshift(a, b) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1148 longobject *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
|
1149 longobject *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
|
1150 { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1151 longobject *z; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1152 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
|
1153 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
|
1154 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
|
1155 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1156 shiftby = getlongvalue((object *)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
|
1157 if (shiftby == -1L && err_occurred()) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1158 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1159 if (shiftby < 0) { |
| 475 | 1160 err_setstr(ValueError, "negative shift count"); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1161 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1162 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1163 if (shiftby > MASK) { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1164 err_setstr(ValueError, "outrageous left shift count"); |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1165 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1166 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1167 if (shiftby % SHIFT == 0) { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1168 wordshift = shiftby / SHIFT; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1169 loshift = 0; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1170 hishift = SHIFT; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1171 newsize = ABS(a->ob_size) + wordshift; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1172 lomask = MASK; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1173 himask = 0; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1174 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1175 else { |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1176 wordshift = shiftby / SHIFT + 1; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1177 loshift = SHIFT - shiftby%SHIFT; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1178 hishift = shiftby % SHIFT; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1179 newsize = ABS(a->ob_size) + wordshift; |
|
443
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1180 lomask = ((digit)1 << hishift) - 1; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1181 himask = MASK ^ lomask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1182 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1183 z = alloclongobject(newsize); |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1184 if (z == NULL) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1185 return NULL; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1186 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
|
1187 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
|
1188 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
|
1189 z->ob_digit[i] = 0; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1190 for (i = wordshift, j = 0; i < newsize; 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
|
1191 if (i > 0) |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1192 z->ob_digit[i-1] |= |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1193 (a->ob_digit[j] << hishift) & himask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1194 z->ob_digit[i] = |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1195 (a->ob_digit[j] >> loshift) & lomask; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1196 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1197 return (object *) 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
|
1198 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1199 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1200 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1201 /* 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
|
1202 |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1203 #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
|
1204 #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
|
1205 |
| 613 | 1206 static object *long_bitwise PROTO((longobject *, int, longobject *)); |
| 1207 static object * | |
| 1208 long_bitwise(a, op, 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
|
1209 longobject *a; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1210 int op; /* '&', '|', '^' */ |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1211 longobject *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
|
1212 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1213 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
|
1214 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
|
1215 int size_a, size_b, size_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
|
1216 longobject *z; |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1217 int i; |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1218 digit diga, digb; |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1219 object *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
|
1220 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1221 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
|
1222 a = (longobject *) long_invert(a); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1223 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
|
1224 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1225 else { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1226 INCREF(a); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1227 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
|
1228 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1229 if (b->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
|
1230 b = (longobject *) long_invert(b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1231 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
|
1232 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1233 else { |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1234 INCREF(b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1235 maskb = 0; |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1236 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1237 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1238 size_a = 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
|
1239 size_b = b->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
|
1240 size_z = MAX(size_a, size_b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1241 z = alloclongobject(size_z); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1242 if (a == NULL || b == NULL || 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
|
1243 XDECREF(a); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1244 XDECREF(b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1245 XDECREF(z); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1246 return 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
|
1247 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1248 |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1249 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
|
1250 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
|
1251 case '^': |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1252 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
|
1253 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
|
1254 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
|
1255 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1256 break; |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1257 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
|
1258 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
|
1259 op = '|'; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1260 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
|
1261 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
|
1262 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
|
1263 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1264 break; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1265 case '|': |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1266 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
|
1267 op = '&'; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1268 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
|
1269 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
|
1270 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
|
1271 } |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1272 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
|
1273 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1274 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1275 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
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 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
|
1281 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
|
1282 } |
|
546
937cbc0be6ec
Fixed bug in long masking ops.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
1283 } |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1284 |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1285 DECREF(a); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1286 DECREF(b); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1287 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
|
1288 if (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
|
1289 return (object *) z; |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1290 v = long_invert(z); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1291 DECREF(z); |
|
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1292 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
|
1293 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1294 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1295 static object * |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1296 long_and(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
|
1297 longobject *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
|
1298 longobject *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
|
1299 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1300 return long_bitwise(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
|
1301 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1302 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1303 static object * |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1304 long_xor(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
|
1305 longobject *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
|
1306 longobject *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
|
1307 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1308 return long_bitwise(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
|
1309 } |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1310 |
|
9f85beb1f7c8
Made the sign use one's complement; implemented shifting and masking operators.
Guido van Rossum <guido@python.org>
parents:
406
diff
changeset
|
1311 static object * |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1312 long_or(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
|
1313 longobject *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
|
1314 longobject *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
|
1315 { |
|
590
f11fae8ee1e4
Changed to 2's complement bitwise ops. Got rid of ZABS etc.
Guido van Rossum <guido@python.org>
parents:
546
diff
changeset
|
1316 return long_bitwise(a, '|', b); |
| 242 | 1317 } |
| 1318 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1319 static int |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1320 long_coerce(pv, pw) |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1321 object **pv; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1322 object **pw; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1323 { |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1324 if (is_intobject(*pw)) { |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1325 *pw = newlongobject(getintvalue(*pw)); |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1326 INCREF(*pv); |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1327 return 0; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1328 } |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1329 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
|
1330 } |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1331 |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1332 static object * |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1333 long_int(v) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1334 object *v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1335 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1336 long x; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1337 x = getlongvalue(v); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1338 if (err_occurred()) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1339 return NULL; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1340 return newintobject(x); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1341 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1342 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1343 static object * |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1344 long_long(v) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1345 object *v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1346 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1347 INCREF(v); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1348 return v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1349 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1350 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1351 static object * |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1352 long_float(v) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1353 object *v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1354 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1355 return newfloatobject(dgetlongvalue(v)); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1356 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1357 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1358 static object * |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1359 long_oct(v) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1360 object *v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1361 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1362 return long_format(v, 8); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1363 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1364 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1365 static object * |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1366 long_hex(v) |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1367 object *v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1368 { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1369 return long_format(v, 16); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1370 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1371 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1372 |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1373 #define UF (unaryfunc) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1374 #define BF (binaryfunc) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1375 #define TF (ternaryfunc) |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1376 #define IF (inquiry) |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1377 |
| 230 | 1378 static number_methods long_as_number = { |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1379 BF long_add, /*nb_add*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1380 BF long_sub, /*nb_subtract*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1381 BF long_mul, /*nb_multiply*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1382 BF long_div, /*nb_divide*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1383 BF long_mod, /*nb_remainder*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1384 BF long_divmod, /*nb_divmod*/ |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1385 TF long_pow, /*nb_power*/ |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1386 UF long_neg, /*nb_negative*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1387 UF long_pos, /*tp_positive*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1388 UF long_abs, /*tp_absolute*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1389 IF long_nonzero,/*tp_nonzero*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1390 UF long_invert, /*nb_invert*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1391 BF long_lshift, /*nb_lshift*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1392 BF long_rshift, /*nb_rshift*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1393 BF long_and, /*nb_and*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1394 BF long_xor, /*nb_xor*/ |
|
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1395 BF long_or, /*nb_or*/ |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1396 (int (*) FPROTO((object **, object **))) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1397 (coercion)long_coerce, /*nb_coerce*/ |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1398 UF long_int, /*nb_int*/ |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1399 UF long_long, /*nb_long*/ |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1400 UF long_float, /*nb_float*/ |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1401 UF long_oct, /*nb_oct*/ |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
958
diff
changeset
|
1402 UF long_hex, /*nb_hex*/ |
| 230 | 1403 }; |
| 1404 | |
| 1405 typeobject Longtype = { | |
| 1406 OB_HEAD_INIT(&Typetype) | |
| 1407 0, | |
| 1408 "long int", | |
| 1409 sizeof(longobject) - sizeof(digit), | |
| 1410 sizeof(digit), | |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1411 (destructor)long_dealloc, /*tp_dealloc*/ |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
1412 0, /*tp_print*/ |
| 230 | 1413 0, /*tp_getattr*/ |
| 1414 0, /*tp_setattr*/ | |
|
743
dbcb49d742a0
Lint stuff (involves casts, yuck!)
Guido van Rossum <guido@python.org>
parents:
613
diff
changeset
|
1415 (int (*) FPROTO((object *, object *))) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1416 (cmpfunc)long_compare, /*tp_compare*/ |
|
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1417 (reprfunc)long_repr, /*tp_repr*/ |
| 230 | 1418 &long_as_number,/*tp_as_number*/ |
| 1419 0, /*tp_as_sequence*/ | |
| 1420 0, /*tp_as_mapping*/ | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1421 (long (*) FPROTO((object *))) |
|
1837
87364d9e3444
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1422 (hashfunc)long_hash, /*tp_hash*/ |
| 230 | 1423 }; |
