blob: 69aede4cc1950417c2ef334278487b1b56fcf027 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Float object implementation */
3
Guido van Rossum2a9096b1990-10-21 22:15:08 +00004/* XXX There should be overflow checks here, but it's hard to check
5 for any kind of float exception without losing portability. */
6
Guido van Rossumc0b618a1997-05-02 03:12:38 +00007#include "Python.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00008
Guido van Rossum3f5da241990-12-20 15:06:42 +00009#include <ctype.h>
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000010
Guido van Rossum9575a441993-04-07 14:06:14 +000011#ifdef i860
12/* Cray APP has bogus definition of HUGE_VAL in <math.h> */
13#undef HUGE_VAL
14#endif
15
Guido van Rossum9d81b551996-06-26 18:27:19 +000016#if defined(HUGE_VAL) && !defined(CHECK)
Guido van Rossum7fa52f81991-12-16 15:43:14 +000017#define CHECK(x) if (errno != 0) ; \
18 else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \
19 else errno = ERANGE
Guido van Rossum9d81b551996-06-26 18:27:19 +000020#endif
21
22#ifndef CHECK
Guido van Rossum7fa52f81991-12-16 15:43:14 +000023#define CHECK(x) /* Don't know how to check */
24#endif
25
Guido van Rossum07e3a7e1995-02-27 10:13:37 +000026#if !defined(__STDC__) && !defined(macintosh)
Tim Petersdbd9ba62000-07-09 03:09:57 +000027extern double fmod(double, double);
28extern double pow(double, double);
Guido van Rossum6923e131990-11-02 17:50:43 +000029#endif
30
Martin v. Löwis01c65262001-03-06 12:14:54 +000031#if defined(sun) && !defined(__SVR4)
Guido van Rossum3c03fa81997-10-31 17:00:30 +000032/* On SunOS4.1 only libm.a exists. Make sure that references to all
33 needed math functions exist in the executable, so that dynamic
34 loading of mathmodule does not fail. */
35double (*_Py_math_funcs_hack[])() = {
36 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor,
37 fmod, log, log10, pow, sin, sinh, sqrt, tan, tanh
38};
39#endif
40
Guido van Rossum93ad0df1997-05-13 21:00:42 +000041/* Special free list -- see comments for same code in intobject.c. */
Guido van Rossum93ad0df1997-05-13 21:00:42 +000042#define BLOCK_SIZE 1000 /* 1K less typical malloc overhead */
Guido van Rossum3fce8831999-03-12 19:43:17 +000043#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
Guido van Rossumf61bbc81999-03-12 00:12:21 +000044#define N_FLOATOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject))
Guido van Rossum3fce8831999-03-12 19:43:17 +000045
Guido van Rossum3fce8831999-03-12 19:43:17 +000046struct _floatblock {
47 struct _floatblock *next;
48 PyFloatObject objects[N_FLOATOBJECTS];
49};
50
51typedef struct _floatblock PyFloatBlock;
52
53static PyFloatBlock *block_list = NULL;
54static PyFloatObject *free_list = NULL;
55
Guido van Rossum93ad0df1997-05-13 21:00:42 +000056static PyFloatObject *
Fred Drakefd99de62000-07-09 05:02:18 +000057fill_free_list(void)
Guido van Rossum93ad0df1997-05-13 21:00:42 +000058{
59 PyFloatObject *p, *q;
Guido van Rossumb18618d2000-05-03 23:44:39 +000060 /* XXX Float blocks escape the object heap. Use PyObject_MALLOC ??? */
61 p = (PyFloatObject *) PyMem_MALLOC(sizeof(PyFloatBlock));
Guido van Rossum93ad0df1997-05-13 21:00:42 +000062 if (p == NULL)
Guido van Rossumb18618d2000-05-03 23:44:39 +000063 return (PyFloatObject *) PyErr_NoMemory();
Guido van Rossum3fce8831999-03-12 19:43:17 +000064 ((PyFloatBlock *)p)->next = block_list;
65 block_list = (PyFloatBlock *)p;
66 p = &((PyFloatBlock *)p)->objects[0];
Guido van Rossum93ad0df1997-05-13 21:00:42 +000067 q = p + N_FLOATOBJECTS;
68 while (--q > p)
Guido van Rossumf61bbc81999-03-12 00:12:21 +000069 q->ob_type = (struct _typeobject *)(q-1);
70 q->ob_type = NULL;
Guido van Rossum93ad0df1997-05-13 21:00:42 +000071 return p + N_FLOATOBJECTS - 1;
72}
73
Guido van Rossumc0b618a1997-05-02 03:12:38 +000074PyObject *
Guido van Rossumc0b618a1997-05-02 03:12:38 +000075PyFloat_FromDouble(double fval)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000076{
Guido van Rossum93ad0df1997-05-13 21:00:42 +000077 register PyFloatObject *op;
78 if (free_list == NULL) {
79 if ((free_list = fill_free_list()) == NULL)
80 return NULL;
81 }
Guido van Rossumb18618d2000-05-03 23:44:39 +000082 /* PyObject_New is inlined */
Guido van Rossum93ad0df1997-05-13 21:00:42 +000083 op = free_list;
Guido van Rossumf61bbc81999-03-12 00:12:21 +000084 free_list = (PyFloatObject *)op->ob_type;
Guido van Rossumb18618d2000-05-03 23:44:39 +000085 PyObject_INIT(op, &PyFloat_Type);
Guido van Rossum2a9096b1990-10-21 22:15:08 +000086 op->ob_fval = fval;
Guido van Rossumc0b618a1997-05-02 03:12:38 +000087 return (PyObject *) op;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000088}
89
Tim Petersef14d732000-09-23 03:39:17 +000090/**************************************************************************
91RED_FLAG 22-Sep-2000 tim
92PyFloat_FromString's pend argument is braindead. Prior to this RED_FLAG,
93
941. If v was a regular string, *pend was set to point to its terminating
95 null byte. That's useless (the caller can find that without any
96 help from this function!).
97
982. If v was a Unicode string, or an object convertible to a character
99 buffer, *pend was set to point into stack trash (the auto temp
100 vector holding the character buffer). That was downright dangerous.
101
102Since we can't change the interface of a public API function, pend is
103still supported but now *officially* useless: if pend is not NULL,
104*pend is set to NULL.
105**************************************************************************/
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000106PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000107PyFloat_FromString(PyObject *v, char **pend)
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000108{
Guido van Rossum4c08d552000-03-10 22:55:18 +0000109 const char *s, *last, *end;
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000110 double x;
Tim Petersef14d732000-09-23 03:39:17 +0000111 char buffer[256]; /* for errors */
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000112#ifdef Py_USING_UNICODE
Tim Petersef14d732000-09-23 03:39:17 +0000113 char s_buffer[256]; /* for objects convertible to a char buffer */
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000114#endif
Guido van Rossum4c08d552000-03-10 22:55:18 +0000115 int len;
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000116
Tim Petersef14d732000-09-23 03:39:17 +0000117 if (pend)
118 *pend = NULL;
Guido van Rossum4c08d552000-03-10 22:55:18 +0000119 if (PyString_Check(v)) {
120 s = PyString_AS_STRING(v);
121 len = PyString_GET_SIZE(v);
122 }
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000123#ifdef Py_USING_UNICODE
Guido van Rossum9e896b32000-04-05 20:11:21 +0000124 else if (PyUnicode_Check(v)) {
Guido van Rossum9e896b32000-04-05 20:11:21 +0000125 if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
126 PyErr_SetString(PyExc_ValueError,
Tim Petersef14d732000-09-23 03:39:17 +0000127 "Unicode float() literal too long to convert");
Guido van Rossum9e896b32000-04-05 20:11:21 +0000128 return NULL;
129 }
Tim Petersef14d732000-09-23 03:39:17 +0000130 if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
Guido van Rossum9e896b32000-04-05 20:11:21 +0000131 PyUnicode_GET_SIZE(v),
132 s_buffer,
133 NULL))
134 return NULL;
135 s = s_buffer;
Trent Micka248fb62000-08-12 21:37:39 +0000136 len = (int)strlen(s);
Guido van Rossum9e896b32000-04-05 20:11:21 +0000137 }
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000138#endif
Guido van Rossum4c08d552000-03-10 22:55:18 +0000139 else if (PyObject_AsCharBuffer(v, &s, &len)) {
140 PyErr_SetString(PyExc_TypeError,
141 "float() needs a string argument");
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000142 return NULL;
Guido van Rossum4c08d552000-03-10 22:55:18 +0000143 }
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000144
Guido van Rossum4c08d552000-03-10 22:55:18 +0000145 last = s + len;
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000146 while (*s && isspace(Py_CHARMASK(*s)))
147 s++;
Tim Petersef14d732000-09-23 03:39:17 +0000148 if (*s == '\0') {
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000149 PyErr_SetString(PyExc_ValueError, "empty string for float()");
150 return NULL;
151 }
Tim Petersef14d732000-09-23 03:39:17 +0000152 /* We don't care about overflow or underflow. If the platform supports
153 * them, infinities and signed zeroes (on underflow) are fine.
154 * However, strtod can return 0 for denormalized numbers, where atof
155 * does not. So (alas!) we special-case a zero result. Note that
156 * whether strtod sets errno on underflow is not defined, so we can't
157 * key off errno.
158 */
Tim Peters858346e2000-09-25 21:01:28 +0000159 PyFPE_START_PROTECT("strtod", return NULL)
Tim Petersef14d732000-09-23 03:39:17 +0000160 x = strtod(s, (char **)&end);
Tim Peters858346e2000-09-25 21:01:28 +0000161 PyFPE_END_PROTECT(x)
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000162 errno = 0;
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000163 /* Believe it or not, Solaris 2.6 can move end *beyond* the null
Tim Petersef14d732000-09-23 03:39:17 +0000164 byte at the end of the string, when the input is inf(inity). */
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000165 if (end > last)
166 end = last;
Tim Petersef14d732000-09-23 03:39:17 +0000167 if (end == s) {
168 sprintf(buffer, "invalid literal for float(): %.200s", s);
169 PyErr_SetString(PyExc_ValueError, buffer);
170 return NULL;
171 }
172 /* Since end != s, the platform made *some* kind of sense out
173 of the input. Trust it. */
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000174 while (*end && isspace(Py_CHARMASK(*end)))
175 end++;
176 if (*end != '\0') {
177 sprintf(buffer, "invalid literal for float(): %.200s", s);
178 PyErr_SetString(PyExc_ValueError, buffer);
179 return NULL;
180 }
Guido van Rossum4c08d552000-03-10 22:55:18 +0000181 else if (end != last) {
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000182 PyErr_SetString(PyExc_ValueError,
183 "null byte in argument for float()");
184 return NULL;
185 }
Tim Petersef14d732000-09-23 03:39:17 +0000186 if (x == 0.0) {
187 /* See above -- may have been strtod being anal
188 about denorms. */
Tim Peters858346e2000-09-25 21:01:28 +0000189 PyFPE_START_PROTECT("atof", return NULL)
Tim Petersef14d732000-09-23 03:39:17 +0000190 x = atof(s);
Tim Peters858346e2000-09-25 21:01:28 +0000191 PyFPE_END_PROTECT(x)
Tim Petersef14d732000-09-23 03:39:17 +0000192 errno = 0; /* whether atof ever set errno is undefined */
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000193 }
Barry Warsaw226ae6c1999-10-12 19:54:53 +0000194 return PyFloat_FromDouble(x);
195}
196
Guido van Rossum234f9421993-06-17 12:35:49 +0000197static void
Fred Drakefd99de62000-07-09 05:02:18 +0000198float_dealloc(PyFloatObject *op)
Guido van Rossum3132a5a1992-03-27 17:28:44 +0000199{
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000200 op->ob_type = (struct _typeobject *)free_list;
Guido van Rossum93ad0df1997-05-13 21:00:42 +0000201 free_list = op;
Guido van Rossum3132a5a1992-03-27 17:28:44 +0000202}
203
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000204double
Fred Drakefd99de62000-07-09 05:02:18 +0000205PyFloat_AsDouble(PyObject *op)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000206{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000207 PyNumberMethods *nb;
208 PyFloatObject *fo;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000209 double val;
210
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000211 if (op && PyFloat_Check(op))
212 return PyFloat_AS_DOUBLE((PyFloatObject*) op);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000213
214 if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
215 nb->nb_float == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000216 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000217 return -1;
218 }
Guido van Rossumb6775db1994-08-01 11:34:53 +0000219
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000220 fo = (PyFloatObject*) (*nb->nb_float) (op);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000221 if (fo == NULL)
222 return -1;
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000223 if (!PyFloat_Check(fo)) {
224 PyErr_SetString(PyExc_TypeError,
225 "nb_float should return float object");
Guido van Rossumb6775db1994-08-01 11:34:53 +0000226 return -1;
227 }
228
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000229 val = PyFloat_AS_DOUBLE(fo);
230 Py_DECREF(fo);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000231
232 return val;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000233}
234
235/* Methods */
236
Guido van Rossum27dec7e1991-06-04 19:42:53 +0000237void
Fred Drakefd99de62000-07-09 05:02:18 +0000238PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000239{
240 register char *cp;
241 /* Subroutine for float_repr and float_print.
242 We want float numbers to be recognizable as such,
243 i.e., they should contain a decimal point or an exponent.
244 However, %g may print the number as an integer;
245 in such cases, we append ".0" to the string. */
Guido van Rossum57072eb1999-12-23 19:00:28 +0000246 sprintf(buf, "%.*g", precision, v->ob_fval);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000247 cp = buf;
248 if (*cp == '-')
249 cp++;
250 for (; *cp != '\0'; cp++) {
251 /* Any non-digit means it's not an integer;
252 this takes care of NAN and INF as well. */
Guido van Rossum9fa2c111995-02-10 17:00:37 +0000253 if (!isdigit(Py_CHARMASK(*cp)))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000254 break;
255 }
256 if (*cp == '\0') {
257 *cp++ = '.';
258 *cp++ = '0';
259 *cp++ = '\0';
260 }
261}
262
Neil Schemenauer32117e52001-01-04 01:44:34 +0000263/* Macro and helper that convert PyObject obj to a C double and store
264 the value in dbl; this replaces the functionality of the coercion
265 slot function */
266
267#define CONVERT_TO_DOUBLE(obj, dbl) \
268 if (PyFloat_Check(obj)) \
269 dbl = PyFloat_AS_DOUBLE(obj); \
270 else if (convert_to_double(&(obj), &(dbl)) < 0) \
271 return obj;
272
273static int
274convert_to_double(PyObject **v,
275 double *dbl)
276{
277 register PyObject *obj = *v;
278
279 if (PyInt_Check(obj)) {
280 *dbl = (double)PyInt_AS_LONG(obj);
281 }
282 else if (PyLong_Check(obj)) {
283 PyFPE_START_PROTECT("convert_to_double", {*v=NULL;return -1;})
284 *dbl = PyLong_AsDouble(obj);
Jeremy Hylton2492a202001-02-01 23:53:05 +0000285 PyFPE_END_PROTECT(*dbl)
Neil Schemenauer32117e52001-01-04 01:44:34 +0000286 }
287 else {
288 Py_INCREF(Py_NotImplemented);
289 *v = Py_NotImplemented;
290 return -1;
291 }
292 return 0;
293}
294
Guido van Rossum57072eb1999-12-23 19:00:28 +0000295/* Precisions used by repr() and str(), respectively.
296
297 The repr() precision (17 significant decimal digits) is the minimal number
298 that is guaranteed to have enough precision so that if the number is read
299 back in the exact same binary value is recreated. This is true for IEEE
300 floating point by design, and also happens to work for all other modern
301 hardware.
302
303 The str() precision is chosen so that in most cases, the rounding noise
304 created by various operations is suppressed, while giving plenty of
305 precision for practical use.
306
307*/
308
309#define PREC_REPR 17
310#define PREC_STR 12
311
312void
Fred Drakefd99de62000-07-09 05:02:18 +0000313PyFloat_AsString(char *buf, PyFloatObject *v)
Guido van Rossum57072eb1999-12-23 19:00:28 +0000314{
315 PyFloat_AsStringEx(buf, v, PREC_STR);
316}
317
Tim Peters72f98e92001-05-08 15:19:57 +0000318void
319PyFloat_AsReprString(char *buf, PyFloatObject *v)
320{
321 PyFloat_AsStringEx(buf, v, PREC_REPR);
322}
323
Guido van Rossum3132a5a1992-03-27 17:28:44 +0000324/* ARGSUSED */
Guido van Rossum90933611991-06-07 16:10:43 +0000325static int
Fred Drakefd99de62000-07-09 05:02:18 +0000326float_print(PyFloatObject *v, FILE *fp, int flags)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000327{
328 char buf[100];
Guido van Rossum57072eb1999-12-23 19:00:28 +0000329 PyFloat_AsStringEx(buf, v, flags&Py_PRINT_RAW ? PREC_STR : PREC_REPR);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000330 fputs(buf, fp);
Guido van Rossum90933611991-06-07 16:10:43 +0000331 return 0;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000332}
333
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000334static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000335float_repr(PyFloatObject *v)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000336{
337 char buf[100];
Guido van Rossum57072eb1999-12-23 19:00:28 +0000338 PyFloat_AsStringEx(buf, v, PREC_REPR);
339 return PyString_FromString(buf);
340}
341
342static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000343float_str(PyFloatObject *v)
Guido van Rossum57072eb1999-12-23 19:00:28 +0000344{
345 char buf[100];
346 PyFloat_AsStringEx(buf, v, PREC_STR);
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000347 return PyString_FromString(buf);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000348}
349
350static int
Fred Drakefd99de62000-07-09 05:02:18 +0000351float_compare(PyFloatObject *v, PyFloatObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000352{
353 double i = v->ob_fval;
354 double j = w->ob_fval;
355 return (i < j) ? -1 : (i > j) ? 1 : 0;
356}
357
Guido van Rossum9bfef441993-03-29 10:43:31 +0000358static long
Fred Drakefd99de62000-07-09 05:02:18 +0000359float_hash(PyFloatObject *v)
Guido van Rossum9bfef441993-03-29 10:43:31 +0000360{
Tim Peters39dce292000-08-15 03:34:48 +0000361 return _Py_HashDouble(v->ob_fval);
Guido van Rossum9bfef441993-03-29 10:43:31 +0000362}
363
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000364static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000365float_add(PyObject *v, PyObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000366{
Neil Schemenauer32117e52001-01-04 01:44:34 +0000367 double a,b;
368 CONVERT_TO_DOUBLE(v, a);
369 CONVERT_TO_DOUBLE(w, b);
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000370 PyFPE_START_PROTECT("add", return 0)
Neil Schemenauer32117e52001-01-04 01:44:34 +0000371 a = a + b;
372 PyFPE_END_PROTECT(a)
373 return PyFloat_FromDouble(a);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000374}
375
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000376static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000377float_sub(PyObject *v, PyObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000378{
Neil Schemenauer32117e52001-01-04 01:44:34 +0000379 double a,b;
380 CONVERT_TO_DOUBLE(v, a);
381 CONVERT_TO_DOUBLE(w, b);
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000382 PyFPE_START_PROTECT("subtract", return 0)
Neil Schemenauer32117e52001-01-04 01:44:34 +0000383 a = a - b;
384 PyFPE_END_PROTECT(a)
385 return PyFloat_FromDouble(a);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000386}
387
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000388static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000389float_mul(PyObject *v, PyObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000390{
Neil Schemenauer32117e52001-01-04 01:44:34 +0000391 double a,b;
392 CONVERT_TO_DOUBLE(v, a);
393 CONVERT_TO_DOUBLE(w, b);
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000394 PyFPE_START_PROTECT("multiply", return 0)
Neil Schemenauer32117e52001-01-04 01:44:34 +0000395 a = a * b;
396 PyFPE_END_PROTECT(a)
397 return PyFloat_FromDouble(a);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000398}
399
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000400static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000401float_div(PyObject *v, PyObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000402{
Neil Schemenauer32117e52001-01-04 01:44:34 +0000403 double a,b;
404 CONVERT_TO_DOUBLE(v, a);
405 CONVERT_TO_DOUBLE(w, b);
406 if (b == 0.0) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000407 PyErr_SetString(PyExc_ZeroDivisionError, "float division");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000408 return NULL;
409 }
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000410 PyFPE_START_PROTECT("divide", return 0)
Neil Schemenauer32117e52001-01-04 01:44:34 +0000411 a = a / b;
412 PyFPE_END_PROTECT(a)
413 return PyFloat_FromDouble(a);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000414}
415
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000416static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000417float_rem(PyObject *v, PyObject *w)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000418{
Guido van Rossum56cd67a1992-01-26 18:16:35 +0000419 double vx, wx;
Guido van Rossum9263e781999-05-06 14:26:34 +0000420 double mod;
Neil Schemenauer32117e52001-01-04 01:44:34 +0000421 CONVERT_TO_DOUBLE(v, vx);
422 CONVERT_TO_DOUBLE(w, wx);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000423 if (wx == 0.0) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000424 PyErr_SetString(PyExc_ZeroDivisionError, "float modulo");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000425 return NULL;
426 }
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000427 PyFPE_START_PROTECT("modulo", return 0)
Guido van Rossum56cd67a1992-01-26 18:16:35 +0000428 mod = fmod(vx, wx);
Guido van Rossum9263e781999-05-06 14:26:34 +0000429 /* note: checking mod*wx < 0 is incorrect -- underflows to
430 0 if wx < sqrt(smallest nonzero double) */
431 if (mod && ((wx < 0) != (mod < 0))) {
Guido van Rossum56cd67a1992-01-26 18:16:35 +0000432 mod += wx;
Guido van Rossum56cd67a1992-01-26 18:16:35 +0000433 }
Guido van Rossum45b83911997-03-14 04:32:50 +0000434 PyFPE_END_PROTECT(mod)
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000435 return PyFloat_FromDouble(mod);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000436}
437
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000438static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000439float_divmod(PyObject *v, PyObject *w)
Guido van Rossumeba1b5e1991-05-05 20:07:00 +0000440{
Guido van Rossum15ecff41991-10-20 20:16:45 +0000441 double vx, wx;
Guido van Rossum9263e781999-05-06 14:26:34 +0000442 double div, mod, floordiv;
Neil Schemenauer32117e52001-01-04 01:44:34 +0000443 CONVERT_TO_DOUBLE(v, vx);
444 CONVERT_TO_DOUBLE(w, wx);
Guido van Rossum15ecff41991-10-20 20:16:45 +0000445 if (wx == 0.0) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000446 PyErr_SetString(PyExc_ZeroDivisionError, "float divmod()");
Guido van Rossum15ecff41991-10-20 20:16:45 +0000447 return NULL;
448 }
Guido van Rossum09e6ad01997-02-14 22:54:21 +0000449 PyFPE_START_PROTECT("divmod", return 0)
Guido van Rossum15ecff41991-10-20 20:16:45 +0000450 mod = fmod(vx, wx);
Tim Peters78fc0b52000-09-16 03:54:24 +0000451 /* fmod is typically exact, so vx-mod is *mathematically* an
Guido van Rossum9263e781999-05-06 14:26:34 +0000452 exact multiple of wx. But this is fp arithmetic, and fp
453 vx - mod is an approximation; the result is that div may
454 not be an exact integral value after the division, although
455 it will always be very close to one.
456 */
Guido van Rossum15ecff41991-10-20 20:16:45 +0000457 div = (vx - mod) / wx;
Guido van Rossum9263e781999-05-06 14:26:34 +0000458 /* note: checking mod*wx < 0 is incorrect -- underflows to
459 0 if wx < sqrt(smallest nonzero double) */
460 if (mod && ((wx < 0) != (mod < 0))) {
Guido van Rossum15ecff41991-10-20 20:16:45 +0000461 mod += wx;
462 div -= 1.0;
463 }
Guido van Rossum9263e781999-05-06 14:26:34 +0000464 /* snap quotient to nearest integral value */
465 floordiv = floor(div);
466 if (div - floordiv > 0.5)
467 floordiv += 1.0;
Guido van Rossum45b83911997-03-14 04:32:50 +0000468 PyFPE_END_PROTECT(div)
Guido van Rossum9263e781999-05-06 14:26:34 +0000469 return Py_BuildValue("(dd)", floordiv, mod);
Guido van Rossumeba1b5e1991-05-05 20:07:00 +0000470}
471
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000472static PyObject *
Neil Schemenauer32117e52001-01-04 01:44:34 +0000473float_pow(PyObject *v, PyObject *w, PyObject *z)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000474{
475 double iv, iw, ix;
Guido van Rossum0b7d02a1994-08-12 12:52:35 +0000476 /* XXX Doesn't handle overflows if z!=None yet; it may never do so :(
477 * The z parameter is really only going to be useful for integers and
478 * long integers. Maybe something clever with logarithms could be done.
479 * [AMK]
480 */
Neil Schemenauer32117e52001-01-04 01:44:34 +0000481 CONVERT_TO_DOUBLE(v, iv);
482 CONVERT_TO_DOUBLE(w, iw);
Tim Petersc54d1902000-10-06 00:36:09 +0000483
484 /* Sort out special cases here instead of relying on pow() */
Tim Peters96685bf2001-08-23 22:31:37 +0000485 if (iw == 0) { /* v**0 is 1, even 0**0 */
Tim Petersc54d1902000-10-06 00:36:09 +0000486 PyFPE_START_PROTECT("pow", return NULL)
487 if ((PyObject *)z != Py_None) {
Neil Schemenauer32117e52001-01-04 01:44:34 +0000488 double iz;
Neil Schemenauer010b0cc2001-01-08 06:29:50 +0000489 CONVERT_TO_DOUBLE(z, iz);
Tim Peters96685bf2001-08-23 22:31:37 +0000490 ix = fmod(1.0, iz);
491 if (ix != 0 && iz < 0)
492 ix += iz;
Guido van Rossum70d93461991-05-28 21:57:39 +0000493 }
Tim Petersc54d1902000-10-06 00:36:09 +0000494 else
495 ix = 1.0;
496 PyFPE_END_PROTECT(ix)
497 return PyFloat_FromDouble(ix);
498 }
Tim Peters96685bf2001-08-23 22:31:37 +0000499 if (iv == 0.0) { /* 0**w is error if w<0, else 1 */
Tim Petersc54d1902000-10-06 00:36:09 +0000500 if (iw < 0.0) {
501 PyErr_SetString(PyExc_ZeroDivisionError,
Fred Drake661ea262000-10-24 19:57:45 +0000502 "0.0 cannot be raised to a negative power");
Tim Petersc54d1902000-10-06 00:36:09 +0000503 return NULL;
504 }
505 return PyFloat_FromDouble(0.0);
506 }
Tim Peters96685bf2001-08-23 22:31:37 +0000507 if (iv < 0.0 && iw != floor(iw)) {
508 PyErr_SetString(PyExc_ValueError,
509 "negative number cannot be raised to a fractional power");
510 return NULL;
Guido van Rossum86c04c21996-08-09 20:50:14 +0000511 }
Tim Peters96685bf2001-08-23 22:31:37 +0000512 errno = 0;
513 PyFPE_START_PROTECT("pow", return NULL)
514 ix = pow(iv, iw);
515 PyFPE_END_PROTECT(ix)
Guido van Rossum7fa52f81991-12-16 15:43:14 +0000516 CHECK(ix);
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000517 if (errno != 0) {
518 /* XXX could it be another type of error? */
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000519 PyErr_SetFromErrno(PyExc_OverflowError);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000520 return NULL;
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000521 }
Tim Petersc54d1902000-10-06 00:36:09 +0000522 if ((PyObject *)z != Py_None) {
Neil Schemenauer32117e52001-01-04 01:44:34 +0000523 double iz;
524 CONVERT_TO_DOUBLE(z, iz);
525 PyFPE_START_PROTECT("pow", return 0)
Tim Peters96685bf2001-08-23 22:31:37 +0000526 ix = fmod(ix, iz); /* XXX To Be Rewritten */
527 if (ix != 0 && ((iv < 0 && iz > 0) || (iv > 0 && iz < 0) )) {
528 ix += iz;
Tim Petersc54d1902000-10-06 00:36:09 +0000529 }
Neil Schemenauer32117e52001-01-04 01:44:34 +0000530 PyFPE_END_PROTECT(ix)
Guido van Rossum0b7d02a1994-08-12 12:52:35 +0000531 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000532 return PyFloat_FromDouble(ix);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000533}
534
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000535static PyObject *
Guido van Rossum4668b002001-08-08 05:00:18 +0000536float_int_div(PyObject *v, PyObject *w)
537{
538 PyObject *t, *r;
539
540 t = float_divmod(v, w);
541 if (t != NULL) {
542 r = PyTuple_GET_ITEM(t, 0);
543 Py_INCREF(r);
544 Py_DECREF(t);
545 return r;
546 }
547 return NULL;
548}
549
550static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000551float_neg(PyFloatObject *v)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000552{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000553 return PyFloat_FromDouble(-v->ob_fval);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000554}
555
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000556static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000557float_pos(PyFloatObject *v)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000558{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000559 Py_INCREF(v);
560 return (PyObject *)v;
Guido van Rossumeba1b5e1991-05-05 20:07:00 +0000561}
562
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000563static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000564float_abs(PyFloatObject *v)
Guido van Rossumeba1b5e1991-05-05 20:07:00 +0000565{
566 if (v->ob_fval < 0)
567 return float_neg(v);
568 else
569 return float_pos(v);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000570}
571
Guido van Rossum50b4ef61991-05-14 11:57:01 +0000572static int
Fred Drakefd99de62000-07-09 05:02:18 +0000573float_nonzero(PyFloatObject *v)
Guido van Rossum50b4ef61991-05-14 11:57:01 +0000574{
575 return v->ob_fval != 0.0;
576}
577
Guido van Rossum234f9421993-06-17 12:35:49 +0000578static int
Fred Drakefd99de62000-07-09 05:02:18 +0000579float_coerce(PyObject **pv, PyObject **pw)
Guido van Rossume6eefc21992-08-14 12:06:52 +0000580{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000581 if (PyInt_Check(*pw)) {
582 long x = PyInt_AsLong(*pw);
583 *pw = PyFloat_FromDouble((double)x);
584 Py_INCREF(*pv);
Guido van Rossume6eefc21992-08-14 12:06:52 +0000585 return 0;
586 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000587 else if (PyLong_Check(*pw)) {
588 *pw = PyFloat_FromDouble(PyLong_AsDouble(*pw));
589 Py_INCREF(*pv);
Guido van Rossume6eefc21992-08-14 12:06:52 +0000590 return 0;
591 }
592 return 1; /* Can't do it */
593}
594
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000595static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000596float_int(PyObject *v)
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000597{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000598 double x = PyFloat_AsDouble(v);
Tim Peters7321ec42001-07-26 20:02:17 +0000599 double wholepart; /* integral portion of x, rounded toward 0 */
600 long aslong; /* (long)wholepart */
601
602 (void)modf(x, &wholepart);
603 /* doubles may have more bits than longs, or vice versa; and casting
604 to long may yield gibberish in either case. What really matters
605 is whether converting back to double again reproduces what we
606 started with. */
607 aslong = (long)wholepart;
608 if ((double)aslong == wholepart)
609 return PyInt_FromLong(aslong);
610 PyErr_SetString(PyExc_OverflowError, "float too large to convert");
611 return NULL;
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000612}
613
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000614static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000615float_long(PyObject *v)
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000616{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000617 double x = PyFloat_AsDouble(v);
618 return PyLong_FromDouble(x);
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000619}
620
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000621static PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +0000622float_float(PyObject *v)
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000623{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000624 Py_INCREF(v);
Guido van Rossum1899c2e1992-09-12 11:09:23 +0000625 return v;
626}
627
628
Tim Peters6d6c1a32001-08-02 04:15:00 +0000629static PyObject *
630float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
631{
632 PyObject *x = Py_False; /* Integer zero */
633 static char *kwlist[] = {"x", 0};
634
635 assert(type == &PyFloat_Type);
636 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
637 return NULL;
638 if (PyString_Check(x))
639 return PyFloat_FromString(x, NULL);
640 return PyNumber_Float(x);
641}
642
643static char float_doc[] =
644"float(x) -> floating point number\n\
645\n\
646Convert a string or number to a floating point number, if possible.";
647
648
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000649static PyNumberMethods float_as_number = {
Guido van Rossumb6775db1994-08-01 11:34:53 +0000650 (binaryfunc)float_add, /*nb_add*/
651 (binaryfunc)float_sub, /*nb_subtract*/
652 (binaryfunc)float_mul, /*nb_multiply*/
653 (binaryfunc)float_div, /*nb_divide*/
654 (binaryfunc)float_rem, /*nb_remainder*/
655 (binaryfunc)float_divmod, /*nb_divmod*/
Guido van Rossum0b7d02a1994-08-12 12:52:35 +0000656 (ternaryfunc)float_pow, /*nb_power*/
Guido van Rossumb6775db1994-08-01 11:34:53 +0000657 (unaryfunc)float_neg, /*nb_negative*/
658 (unaryfunc)float_pos, /*nb_positive*/
659 (unaryfunc)float_abs, /*nb_absolute*/
660 (inquiry)float_nonzero, /*nb_nonzero*/
Guido van Rossum27acb331991-10-24 14:55:28 +0000661 0, /*nb_invert*/
662 0, /*nb_lshift*/
663 0, /*nb_rshift*/
664 0, /*nb_and*/
665 0, /*nb_xor*/
666 0, /*nb_or*/
Guido van Rossumb6775db1994-08-01 11:34:53 +0000667 (coercion)float_coerce, /*nb_coerce*/
668 (unaryfunc)float_int, /*nb_int*/
669 (unaryfunc)float_long, /*nb_long*/
670 (unaryfunc)float_float, /*nb_float*/
Guido van Rossum4668b002001-08-08 05:00:18 +0000671 0, /* nb_oct */
672 0, /* nb_hex */
673 0, /* nb_inplace_add */
674 0, /* nb_inplace_subtract */
675 0, /* nb_inplace_multiply */
676 0, /* nb_inplace_divide */
677 0, /* nb_inplace_remainder */
678 0, /* nb_inplace_power */
679 0, /* nb_inplace_lshift */
680 0, /* nb_inplace_rshift */
681 0, /* nb_inplace_and */
682 0, /* nb_inplace_xor */
683 0, /* nb_inplace_or */
684 float_int_div, /* nb_floor_divide */
685 float_div, /* nb_true_divide */
686 0, /* nb_inplace_floor_divide */
687 0, /* nb_inplace_true_divide */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000688};
689
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000690PyTypeObject PyFloat_Type = {
691 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000692 0,
693 "float",
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000694 sizeof(PyFloatObject),
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000695 0,
Tim Peters6d6c1a32001-08-02 04:15:00 +0000696 (destructor)float_dealloc, /* tp_dealloc */
697 (printfunc)float_print, /* tp_print */
698 0, /* tp_getattr */
699 0, /* tp_setattr */
700 (cmpfunc)float_compare, /* tp_compare */
701 (reprfunc)float_repr, /* tp_repr */
702 &float_as_number, /* tp_as_number */
703 0, /* tp_as_sequence */
704 0, /* tp_as_mapping */
705 (hashfunc)float_hash, /* tp_hash */
706 0, /* tp_call */
707 (reprfunc)float_str, /* tp_str */
708 PyObject_GenericGetAttr, /* tp_getattro */
709 0, /* tp_setattro */
710 0, /* tp_as_buffer */
711 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
712 float_doc, /* tp_doc */
713 0, /* tp_traverse */
714 0, /* tp_clear */
715 0, /* tp_richcompare */
716 0, /* tp_weaklistoffset */
717 0, /* tp_iter */
718 0, /* tp_iternext */
719 0, /* tp_methods */
720 0, /* tp_members */
721 0, /* tp_getset */
722 0, /* tp_base */
723 0, /* tp_dict */
724 0, /* tp_descr_get */
725 0, /* tp_descr_set */
726 0, /* tp_dictoffset */
727 0, /* tp_init */
728 0, /* tp_alloc */
729 float_new, /* tp_new */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000730};
Guido van Rossumfbbd57e1997-08-05 02:16:08 +0000731
732void
Fred Drakefd99de62000-07-09 05:02:18 +0000733PyFloat_Fini(void)
Guido van Rossumfbbd57e1997-08-05 02:16:08 +0000734{
Guido van Rossum3fce8831999-03-12 19:43:17 +0000735 PyFloatObject *p;
736 PyFloatBlock *list, *next;
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000737 int i;
738 int bc, bf; /* block count, number of freed blocks */
739 int frem, fsum; /* remaining unfreed floats per block, total */
740
741 bc = 0;
742 bf = 0;
743 fsum = 0;
744 list = block_list;
745 block_list = NULL;
Guido van Rossumd7b5fb81999-03-19 20:59:40 +0000746 free_list = NULL;
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000747 while (list != NULL) {
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000748 bc++;
749 frem = 0;
Guido van Rossumd7b5fb81999-03-19 20:59:40 +0000750 for (i = 0, p = &list->objects[0];
751 i < N_FLOATOBJECTS;
752 i++, p++) {
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000753 if (PyFloat_Check(p) && p->ob_refcnt != 0)
754 frem++;
755 }
Guido van Rossum3fce8831999-03-12 19:43:17 +0000756 next = list->next;
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000757 if (frem) {
Guido van Rossum3fce8831999-03-12 19:43:17 +0000758 list->next = block_list;
759 block_list = list;
Guido van Rossumd7b5fb81999-03-19 20:59:40 +0000760 for (i = 0, p = &list->objects[0];
761 i < N_FLOATOBJECTS;
762 i++, p++) {
763 if (!PyFloat_Check(p) || p->ob_refcnt == 0) {
764 p->ob_type = (struct _typeobject *)
765 free_list;
766 free_list = p;
767 }
768 }
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000769 }
770 else {
Guido van Rossumb18618d2000-05-03 23:44:39 +0000771 PyMem_FREE(list); /* XXX PyObject_FREE ??? */
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000772 bf++;
773 }
774 fsum += frem;
Guido van Rossum3fce8831999-03-12 19:43:17 +0000775 list = next;
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000776 }
Guido van Rossum3fce8831999-03-12 19:43:17 +0000777 if (!Py_VerboseFlag)
778 return;
779 fprintf(stderr, "# cleanup floats");
780 if (!fsum) {
781 fprintf(stderr, "\n");
782 }
783 else {
784 fprintf(stderr,
785 ": %d unfreed float%s in %d out of %d block%s\n",
786 fsum, fsum == 1 ? "" : "s",
787 bc - bf, bc, bc == 1 ? "" : "s");
788 }
789 if (Py_VerboseFlag > 1) {
790 list = block_list;
791 while (list != NULL) {
Guido van Rossumd7b5fb81999-03-19 20:59:40 +0000792 for (i = 0, p = &list->objects[0];
793 i < N_FLOATOBJECTS;
794 i++, p++) {
Guido van Rossum3fce8831999-03-12 19:43:17 +0000795 if (PyFloat_Check(p) && p->ob_refcnt != 0) {
796 char buf[100];
797 PyFloat_AsString(buf, p);
798 fprintf(stderr,
Fred Drakea44d3532000-06-30 15:01:00 +0000799 "# <float at %p, refcnt=%d, val=%s>\n",
800 p, p->ob_refcnt, buf);
Guido van Rossum3fce8831999-03-12 19:43:17 +0000801 }
802 }
803 list = list->next;
Guido van Rossumf61bbc81999-03-12 00:12:21 +0000804 }
805 }
Guido van Rossumfbbd57e1997-08-05 02:16:08 +0000806}