Mercurial > cpython-lru_cache-weakref
annotate Objects/floatobject.c @ 20010:d03c19db3094 legacy-trunk
Document new file() constructor, with the body of open()'s text, plus a
"new in 2.2" blurb at the end. Replace open()'s text by pointing back
to file().
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Thu, 20 Sep 2001 19:55:29 +0000 |
| parents | da00188d5270 |
| children | 2983b54256c7 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Float object implementation */ |
| 3 | |
| 27 | 4 /* XXX There should be overflow checks here, but it's hard to check |
| 5 for any kind of float exception without losing portability. */ | |
| 6 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
7 #include "Python.h" |
| 6 | 8 |
| 86 | 9 #include <ctype.h> |
| 6 | 10 |
|
2433
6cbd2830b5a2
for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents:
2327
diff
changeset
|
11 #if !defined(__STDC__) && !defined(macintosh) |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
12 extern double fmod(double, double); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
13 extern double pow(double, double); |
|
60
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
14 #endif |
|
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
15 |
|
16999
eee7d0c5ae59
Avoid giving prototypes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents:
16401
diff
changeset
|
16 #if defined(sun) && !defined(__SVR4) |
|
6537
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
17 /* On SunOS4.1 only libm.a exists. Make sure that references to all |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
18 needed math functions exist in the executable, so that dynamic |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
19 loading of mathmodule does not fail. */ |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
20 double (*_Py_math_funcs_hack[])() = { |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
21 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
22 fmod, log, log10, pow, sin, sinh, sqrt, tan, tanh |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
23 }; |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
24 #endif |
|
25505e563b37
Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents:
5936
diff
changeset
|
25 |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
26 /* Special free list -- see comments for same code in intobject.c. */ |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
27 #define BLOCK_SIZE 1000 /* 1K less typical malloc overhead */ |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
28 #define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */ |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
29 #define N_FLOATOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject)) |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
30 |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
31 struct _floatblock { |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
32 struct _floatblock *next; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
33 PyFloatObject objects[N_FLOATOBJECTS]; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
34 }; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
35 |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
36 typedef struct _floatblock PyFloatBlock; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
37 |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
38 static PyFloatBlock *block_list = NULL; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
39 static PyFloatObject *free_list = NULL; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
40 |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
41 static PyFloatObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
42 fill_free_list(void) |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
43 { |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
44 PyFloatObject *p, *q; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
45 /* XXX Float blocks escape the object heap. Use PyObject_MALLOC ??? */ |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
46 p = (PyFloatObject *) PyMem_MALLOC(sizeof(PyFloatBlock)); |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
47 if (p == NULL) |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
48 return (PyFloatObject *) PyErr_NoMemory(); |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
49 ((PyFloatBlock *)p)->next = block_list; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
50 block_list = (PyFloatBlock *)p; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
51 p = &((PyFloatBlock *)p)->objects[0]; |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
52 q = p + N_FLOATOBJECTS; |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
53 while (--q > p) |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
54 q->ob_type = (struct _typeobject *)(q-1); |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
55 q->ob_type = NULL; |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
56 return p + N_FLOATOBJECTS - 1; |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
57 } |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
58 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
59 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
60 PyFloat_FromDouble(double fval) |
| 6 | 61 { |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
62 register PyFloatObject *op; |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
63 if (free_list == NULL) { |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
64 if ((free_list = fill_free_list()) == NULL) |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
65 return NULL; |
|
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
66 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
67 /* PyObject_New is inlined */ |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
68 op = free_list; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
69 free_list = (PyFloatObject *)op->ob_type; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
70 PyObject_INIT(op, &PyFloat_Type); |
| 27 | 71 op->ob_fval = fval; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
72 return (PyObject *) op; |
| 6 | 73 } |
| 74 | |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
75 /************************************************************************** |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
76 RED_FLAG 22-Sep-2000 tim |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
77 PyFloat_FromString's pend argument is braindead. Prior to this RED_FLAG, |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
78 |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
79 1. If v was a regular string, *pend was set to point to its terminating |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
80 null byte. That's useless (the caller can find that without any |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
81 help from this function!). |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
82 |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
83 2. If v was a Unicode string, or an object convertible to a character |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
84 buffer, *pend was set to point into stack trash (the auto temp |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
85 vector holding the character buffer). That was downright dangerous. |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
86 |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
87 Since we can't change the interface of a public API function, pend is |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
88 still supported but now *officially* useless: if pend is not NULL, |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
89 *pend is set to NULL. |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
90 **************************************************************************/ |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
91 PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
92 PyFloat_FromString(PyObject *v, char **pend) |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
93 { |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
94 const char *s, *last, *end; |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
95 double x; |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
96 char buffer[256]; /* for errors */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19051
diff
changeset
|
97 #ifdef Py_USING_UNICODE |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
98 char s_buffer[256]; /* for objects convertible to a char buffer */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19051
diff
changeset
|
99 #endif |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
100 int len; |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
101 |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
102 if (pend) |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
103 *pend = NULL; |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
104 if (PyString_Check(v)) { |
|
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
105 s = PyString_AS_STRING(v); |
|
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
106 len = PyString_GET_SIZE(v); |
|
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
107 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19051
diff
changeset
|
108 #ifdef Py_USING_UNICODE |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
109 else if (PyUnicode_Check(v)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
110 if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
111 PyErr_SetString(PyExc_ValueError, |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
112 "Unicode float() literal too long to convert"); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
113 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
114 } |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
115 if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v), |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
116 PyUnicode_GET_SIZE(v), |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
117 s_buffer, |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
118 NULL)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
119 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
120 s = s_buffer; |
|
13944
648ba4044455
Clean up a warning on Win64. The downcast of the strlen size_t
Trent Mick <trentm@activestate.com>
parents:
13761
diff
changeset
|
121 len = (int)strlen(s); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11969
diff
changeset
|
122 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19051
diff
changeset
|
123 #endif |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
124 else if (PyObject_AsCharBuffer(v, &s, &len)) { |
|
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
125 PyErr_SetString(PyExc_TypeError, |
|
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
126 "float() needs a string argument"); |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
127 return NULL; |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
128 } |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
129 |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
130 last = s + len; |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
131 while (*s && isspace(Py_CHARMASK(*s))) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
132 s++; |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
133 if (*s == '\0') { |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
134 PyErr_SetString(PyExc_ValueError, "empty string for float()"); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
135 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
136 } |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
137 /* We don't care about overflow or underflow. If the platform supports |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
138 * them, infinities and signed zeroes (on underflow) are fine. |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
139 * However, strtod can return 0 for denormalized numbers, where atof |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
140 * does not. So (alas!) we special-case a zero result. Note that |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
141 * whether strtod sets errno on underflow is not defined, so we can't |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
142 * key off errno. |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
143 */ |
|
14851
5449302c4d2e
Replace SIGFPE paranoia around strtod and atof. I don't believe these
Tim Peters <tim.peters@gmail.com>
parents:
14783
diff
changeset
|
144 PyFPE_START_PROTECT("strtod", return NULL) |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
145 x = strtod(s, (char **)&end); |
|
14851
5449302c4d2e
Replace SIGFPE paranoia around strtod and atof. I don't believe these
Tim Peters <tim.peters@gmail.com>
parents:
14783
diff
changeset
|
146 PyFPE_END_PROTECT(x) |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
147 errno = 0; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
148 /* Believe it or not, Solaris 2.6 can move end *beyond* the null |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
149 byte at the end of the string, when the input is inf(inity). */ |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
150 if (end > last) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
151 end = last; |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
152 if (end == s) { |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
153 sprintf(buffer, "invalid literal for float(): %.200s", s); |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
154 PyErr_SetString(PyExc_ValueError, buffer); |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
155 return NULL; |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
156 } |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
157 /* Since end != s, the platform made *some* kind of sense out |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
158 of the input. Trust it. */ |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
159 while (*end && isspace(Py_CHARMASK(*end))) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
160 end++; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
161 if (*end != '\0') { |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
162 sprintf(buffer, "invalid literal for float(): %.200s", s); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
163 PyErr_SetString(PyExc_ValueError, buffer); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
164 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
165 } |
|
11969
74b7213fb609
Many changes for Unicode, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
166 else if (end != last) { |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
167 PyErr_SetString(PyExc_ValueError, |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
168 "null byte in argument for float()"); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
169 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
170 } |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
171 if (x == 0.0) { |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
172 /* See above -- may have been strtod being anal |
|
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
173 about denorms. */ |
|
14851
5449302c4d2e
Replace SIGFPE paranoia around strtod and atof. I don't believe these
Tim Peters <tim.peters@gmail.com>
parents:
14783
diff
changeset
|
174 PyFPE_START_PROTECT("atof", return NULL) |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
175 x = atof(s); |
|
14851
5449302c4d2e
Replace SIGFPE paranoia around strtod and atof. I don't believe these
Tim Peters <tim.peters@gmail.com>
parents:
14783
diff
changeset
|
176 PyFPE_END_PROTECT(x) |
|
14783
77eddddbb7cc
Fix for SF bug 110624: float literals behave inconsistently.
Tim Peters <tim.peters@gmail.com>
parents:
14616
diff
changeset
|
177 errno = 0; /* whether atof ever set errno is undefined */ |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
178 } |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
179 return PyFloat_FromDouble(x); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
180 } |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
10833
diff
changeset
|
181 |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
182 static void |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
183 float_dealloc(PyFloatObject *op) |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
184 { |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
185 op->ob_type = (struct _typeobject *)free_list; |
|
5504
c88b9b868995
Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
186 free_list = op; |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
187 } |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
188 |
| 6 | 189 double |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
190 PyFloat_AsDouble(PyObject *op) |
| 6 | 191 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
192 PyNumberMethods *nb; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
193 PyFloatObject *fo; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
194 double val; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
195 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
196 if (op && PyFloat_Check(op)) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
197 return PyFloat_AS_DOUBLE((PyFloatObject*) op); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
198 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
199 if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL || |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
200 nb->nb_float == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
201 PyErr_BadArgument(); |
| 6 | 202 return -1; |
| 203 } | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
204 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
205 fo = (PyFloatObject*) (*nb->nb_float) (op); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
206 if (fo == NULL) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
207 return -1; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
208 if (!PyFloat_Check(fo)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
209 PyErr_SetString(PyExc_TypeError, |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
210 "nb_float should return float object"); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
211 return -1; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
212 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
213 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
214 val = PyFloat_AS_DOUBLE(fo); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
215 Py_DECREF(fo); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
216 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
217 return val; |
| 6 | 218 } |
| 219 | |
| 220 /* Methods */ | |
| 221 | |
|
268
0fe2471166f0
Export float_buf_repr() interface, for marshalling of floats.
Guido van Rossum <guido@python.org>
parents:
249
diff
changeset
|
222 void |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
223 PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision) |
| 6 | 224 { |
| 225 register char *cp; | |
| 226 /* Subroutine for float_repr and float_print. | |
| 227 We want float numbers to be recognizable as such, | |
| 228 i.e., they should contain a decimal point or an exponent. | |
| 229 However, %g may print the number as an integer; | |
| 230 in such cases, we append ".0" to the string. */ | |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
231 sprintf(buf, "%.*g", precision, v->ob_fval); |
| 6 | 232 cp = buf; |
| 233 if (*cp == '-') | |
| 234 cp++; | |
| 235 for (; *cp != '\0'; cp++) { | |
| 236 /* Any non-digit means it's not an integer; | |
| 237 this takes care of NAN and INF as well. */ | |
|
2308
14b126d0b5be
use Py_CHARMASK; and don't check for neg. float to the float power here
Guido van Rossum <guido@python.org>
parents:
2156
diff
changeset
|
238 if (!isdigit(Py_CHARMASK(*cp))) |
| 6 | 239 break; |
| 240 } | |
| 241 if (*cp == '\0') { | |
| 242 *cp++ = '.'; | |
| 243 *cp++ = '0'; | |
| 244 *cp++ = '\0'; | |
| 245 } | |
| 246 } | |
| 247 | |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
248 /* Macro and helper that convert PyObject obj to a C double and store |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
249 the value in dbl; this replaces the functionality of the coercion |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
250 slot function */ |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
251 |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
252 #define CONVERT_TO_DOUBLE(obj, dbl) \ |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
253 if (PyFloat_Check(obj)) \ |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
254 dbl = PyFloat_AS_DOUBLE(obj); \ |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
255 else if (convert_to_double(&(obj), &(dbl)) < 0) \ |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
256 return obj; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
257 |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
258 static int |
|
19674
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
259 convert_to_double(PyObject **v, double *dbl) |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
260 { |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
261 register PyObject *obj = *v; |
|
19674
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
262 |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
263 if (PyInt_Check(obj)) { |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
264 *dbl = (double)PyInt_AS_LONG(obj); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
265 } |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
266 else if (PyLong_Check(obj)) { |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
267 *dbl = PyLong_AsDouble(obj); |
|
19674
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
268 if (*dbl == -1.0 && PyErr_Occurred()) { |
|
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
269 *v = NULL; |
|
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
270 return -1; |
|
715244108faa
Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
271 } |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
272 } |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
273 else { |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
274 Py_INCREF(Py_NotImplemented); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
275 *v = Py_NotImplemented; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
276 return -1; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
277 } |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
278 return 0; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
279 } |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
280 |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
281 /* Precisions used by repr() and str(), respectively. |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
282 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
283 The repr() precision (17 significant decimal digits) is the minimal number |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
284 that is guaranteed to have enough precision so that if the number is read |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
285 back in the exact same binary value is recreated. This is true for IEEE |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
286 floating point by design, and also happens to work for all other modern |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
287 hardware. |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
288 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
289 The str() precision is chosen so that in most cases, the rounding noise |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
290 created by various operations is suppressed, while giving plenty of |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
291 precision for practical use. |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
292 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
293 */ |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
294 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
295 #define PREC_REPR 17 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
296 #define PREC_STR 12 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
297 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
298 void |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
299 PyFloat_AsString(char *buf, PyFloatObject *v) |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
300 { |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
301 PyFloat_AsStringEx(buf, v, PREC_STR); |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
302 } |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
303 |
|
17707
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
304 void |
|
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
305 PyFloat_AsReprString(char *buf, PyFloatObject *v) |
|
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
306 { |
|
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
307 PyFloat_AsStringEx(buf, v, PREC_REPR); |
|
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
308 } |
|
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17029
diff
changeset
|
309 |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
310 /* ARGSUSED */ |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
268
diff
changeset
|
311 static int |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
312 float_print(PyFloatObject *v, FILE *fp, int flags) |
| 6 | 313 { |
| 314 char buf[100]; | |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
315 PyFloat_AsStringEx(buf, v, flags&Py_PRINT_RAW ? PREC_STR : PREC_REPR); |
| 6 | 316 fputs(buf, fp); |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
268
diff
changeset
|
317 return 0; |
| 6 | 318 } |
| 319 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
320 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
321 float_repr(PyFloatObject *v) |
| 6 | 322 { |
| 323 char buf[100]; | |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
324 PyFloat_AsStringEx(buf, v, PREC_REPR); |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
325 return PyString_FromString(buf); |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
326 } |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
327 |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
328 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
329 float_str(PyFloatObject *v) |
|
11631
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
330 { |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
331 char buf[100]; |
|
cf7a0f1b7b48
Implement the other easy thing: repr() of a float now uses %.17g,
Guido van Rossum <guido@python.org>
parents:
11383
diff
changeset
|
332 PyFloat_AsStringEx(buf, v, PREC_STR); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
333 return PyString_FromString(buf); |
| 6 | 334 } |
| 335 | |
| 336 static int | |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
337 float_compare(PyFloatObject *v, PyFloatObject *w) |
| 6 | 338 { |
| 339 double i = v->ob_fval; | |
| 340 double j = w->ob_fval; | |
| 341 return (i < j) ? -1 : (i > j) ? 1 : 0; | |
| 342 } | |
| 343 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
344 static long |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
345 float_hash(PyFloatObject *v) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
346 { |
|
13976
5ada9fa54801
Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
Tim Peters <tim.peters@gmail.com>
parents:
13944
diff
changeset
|
347 return _Py_HashDouble(v->ob_fval); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
348 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
349 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
350 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
351 float_add(PyObject *v, PyObject *w) |
| 6 | 352 { |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
353 double a,b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
354 CONVERT_TO_DOUBLE(v, a); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
355 CONVERT_TO_DOUBLE(w, b); |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
356 PyFPE_START_PROTECT("add", return 0) |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
357 a = a + b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
358 PyFPE_END_PROTECT(a) |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
359 return PyFloat_FromDouble(a); |
| 6 | 360 } |
| 361 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
362 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
363 float_sub(PyObject *v, PyObject *w) |
| 6 | 364 { |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
365 double a,b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
366 CONVERT_TO_DOUBLE(v, a); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
367 CONVERT_TO_DOUBLE(w, b); |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
368 PyFPE_START_PROTECT("subtract", return 0) |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
369 a = a - b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
370 PyFPE_END_PROTECT(a) |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
371 return PyFloat_FromDouble(a); |
| 6 | 372 } |
| 373 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
374 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
375 float_mul(PyObject *v, PyObject *w) |
| 6 | 376 { |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
377 double a,b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
378 CONVERT_TO_DOUBLE(v, a); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
379 CONVERT_TO_DOUBLE(w, b); |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
380 PyFPE_START_PROTECT("multiply", return 0) |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
381 a = a * b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
382 PyFPE_END_PROTECT(a) |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
383 return PyFloat_FromDouble(a); |
| 6 | 384 } |
| 385 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
386 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
387 float_div(PyObject *v, PyObject *w) |
| 6 | 388 { |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
389 double a,b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
390 CONVERT_TO_DOUBLE(v, a); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
391 CONVERT_TO_DOUBLE(w, b); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
392 if (b == 0.0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
393 PyErr_SetString(PyExc_ZeroDivisionError, "float division"); |
| 6 | 394 return NULL; |
| 395 } | |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
396 PyFPE_START_PROTECT("divide", return 0) |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
397 a = a / b; |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
398 PyFPE_END_PROTECT(a) |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
399 return PyFloat_FromDouble(a); |
| 6 | 400 } |
| 401 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
402 static PyObject * |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
403 float_classic_div(PyObject *v, PyObject *w) |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
404 { |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
405 double a,b; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
406 CONVERT_TO_DOUBLE(v, a); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
407 CONVERT_TO_DOUBLE(w, b); |
|
19673
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19666
diff
changeset
|
408 if (Py_DivisionWarningFlag >= 2 && |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
409 PyErr_Warn(PyExc_DeprecationWarning, "classic float division") < 0) |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
410 return NULL; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
411 if (b == 0.0) { |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
412 PyErr_SetString(PyExc_ZeroDivisionError, "float division"); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
413 return NULL; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
414 } |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
415 PyFPE_START_PROTECT("divide", return 0) |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
416 a = a / b; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
417 PyFPE_END_PROTECT(a) |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
418 return PyFloat_FromDouble(a); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
419 } |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
420 |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
421 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
422 float_rem(PyObject *v, PyObject *w) |
| 6 | 423 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
424 double vx, wx; |
| 10833 | 425 double mod; |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
426 CONVERT_TO_DOUBLE(v, vx); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
427 CONVERT_TO_DOUBLE(w, wx); |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
428 if (wx == 0.0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
429 PyErr_SetString(PyExc_ZeroDivisionError, "float modulo"); |
| 6 | 430 return NULL; |
| 431 } | |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
432 PyFPE_START_PROTECT("modulo", return 0) |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
433 mod = fmod(vx, wx); |
| 10833 | 434 /* note: checking mod*wx < 0 is incorrect -- underflows to |
| 435 0 if wx < sqrt(smallest nonzero double) */ | |
| 436 if (mod && ((wx < 0) != (mod < 0))) { | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
437 mod += wx; |
| 6 | 438 } |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5118
diff
changeset
|
439 PyFPE_END_PROTECT(mod) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
440 return PyFloat_FromDouble(mod); |
| 6 | 441 } |
| 442 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
443 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
444 float_divmod(PyObject *v, PyObject *w) |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
445 { |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
446 double vx, wx; |
| 10833 | 447 double div, mod, floordiv; |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
448 CONVERT_TO_DOUBLE(v, vx); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
449 CONVERT_TO_DOUBLE(w, wx); |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
450 if (wx == 0.0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
451 PyErr_SetString(PyExc_ZeroDivisionError, "float divmod()"); |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
452 return NULL; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
453 } |
|
5118
002865af55e5
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4933
diff
changeset
|
454 PyFPE_START_PROTECT("divmod", return 0) |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
455 mod = fmod(vx, wx); |
|
14616
284508c653c7
Fixed legit gripe from c.l.py that math.fmod docs aren't confusing enough.
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
456 /* fmod is typically exact, so vx-mod is *mathematically* an |
| 10833 | 457 exact multiple of wx. But this is fp arithmetic, and fp |
| 458 vx - mod is an approximation; the result is that div may | |
| 459 not be an exact integral value after the division, although | |
| 460 it will always be very close to one. | |
| 461 */ | |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
462 div = (vx - mod) / wx; |
| 10833 | 463 /* note: checking mod*wx < 0 is incorrect -- underflows to |
| 464 0 if wx < sqrt(smallest nonzero double) */ | |
| 465 if (mod && ((wx < 0) != (mod < 0))) { | |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
466 mod += wx; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
467 div -= 1.0; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
468 } |
| 10833 | 469 /* snap quotient to nearest integral value */ |
| 470 floordiv = floor(div); | |
| 471 if (div - floordiv > 0.5) | |
| 472 floordiv += 1.0; | |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5118
diff
changeset
|
473 PyFPE_END_PROTECT(div) |
| 10833 | 474 return Py_BuildValue("(dd)", floordiv, mod); |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
475 } |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
476 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
477 static PyObject * |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
478 float_pow(PyObject *v, PyObject *w, PyObject *z) |
| 6 | 479 { |
| 480 double iv, iw, ix; | |
|
19666
cf65ebf87560
New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents:
19633
diff
changeset
|
481 |
|
cf65ebf87560
New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents:
19633
diff
changeset
|
482 if ((PyObject *)z != Py_None) { |
|
19719
cdfdd5359411
Make the error msgs in our pow() implementations consistent.
Tim Peters <tim.peters@gmail.com>
parents:
19674
diff
changeset
|
483 PyErr_SetString(PyExc_TypeError, "pow() 3rd argument not " |
|
19753
c0580d8c193e
Better error msg for 3-arg pow with a float argument.
Tim Peters <tim.peters@gmail.com>
parents:
19750
diff
changeset
|
484 "allowed unless all arguments are integers"); |
|
19666
cf65ebf87560
New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents:
19633
diff
changeset
|
485 return NULL; |
|
cf65ebf87560
New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents:
19633
diff
changeset
|
486 } |
|
cf65ebf87560
New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents:
19633
diff
changeset
|
487 |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
488 CONVERT_TO_DOUBLE(v, iv); |
|
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
489 CONVERT_TO_DOUBLE(w, iw); |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
490 |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
491 /* Sort out special cases here instead of relying on pow() */ |
|
19457
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
492 if (iw == 0) { /* v**0 is 1, even 0**0 */ |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
493 PyFPE_START_PROTECT("pow", return NULL) |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
494 if ((PyObject *)z != Py_None) { |
|
15723
ac7ae3ead88a
Make float a new style number type.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
495 double iz; |
|
15761
95ee79dfd746
Fix a silly bug in float_pow. Sorry Tim.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15723
diff
changeset
|
496 CONVERT_TO_DOUBLE(z, iz); |
|
19457
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
497 ix = fmod(1.0, iz); |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
498 if (ix != 0 && iz < 0) |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
499 ix += iz; |
|
249
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
500 } |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
501 else |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
502 ix = 1.0; |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
503 PyFPE_END_PROTECT(ix) |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
504 return PyFloat_FromDouble(ix); |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
505 } |
|
19457
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
506 if (iv == 0.0) { /* 0**w is error if w<0, else 1 */ |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
507 if (iw < 0.0) { |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
508 PyErr_SetString(PyExc_ZeroDivisionError, |
| 15318 | 509 "0.0 cannot be raised to a negative power"); |
|
15041
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
510 return NULL; |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
511 } |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
512 return PyFloat_FromDouble(0.0); |
|
7eefde90ec0e
SF bug 115831 and Ping's SF patch 101751, 0.0**-2.0 returns inf rather than
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
513 } |
|
19457
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
514 if (iv < 0.0 && iw != floor(iw)) { |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
515 PyErr_SetString(PyExc_ValueError, |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
516 "negative number cannot be raised to a fractional power"); |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
517 return NULL; |
|
3984
0613f17dcfd8
Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents:
3704
diff
changeset
|
518 } |
|
19457
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
519 errno = 0; |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
520 PyFPE_START_PROTECT("pow", return NULL) |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
521 ix = pow(iv, iw); |
|
6c2b7b624ef2
float_pow: Put *all* of the burden on the libm pow in normal
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
522 PyFPE_END_PROTECT(ix) |
|
19750
35b6a1d0b1e0
Rework the way we try to check for libm overflow, given that C99 no longer
Tim Peters <tim.peters@gmail.com>
parents:
19719
diff
changeset
|
523 Py_SET_ERANGE_IF_OVERFLOW(ix); |
| 27 | 524 if (errno != 0) { |
| 525 /* XXX could it be another type of error? */ | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
526 PyErr_SetFromErrno(PyExc_OverflowError); |
| 6 | 527 return NULL; |
| 27 | 528 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
529 return PyFloat_FromDouble(ix); |
| 6 | 530 } |
| 531 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
532 static PyObject * |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
533 float_int_div(PyObject *v, PyObject *w) |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
534 { |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
535 PyObject *t, *r; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
536 |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
537 t = float_divmod(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
538 if (t != NULL) { |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
539 r = PyTuple_GET_ITEM(t, 0); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
540 Py_INCREF(r); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
541 Py_DECREF(t); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
542 return r; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
543 } |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
544 return NULL; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
545 } |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
546 |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
547 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
548 float_neg(PyFloatObject *v) |
| 6 | 549 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
550 return PyFloat_FromDouble(-v->ob_fval); |
| 6 | 551 } |
| 552 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
553 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
554 float_pos(PyFloatObject *v) |
| 6 | 555 { |
|
19879
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
556 if (PyFloat_CheckExact(v)) { |
|
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
557 Py_INCREF(v); |
|
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
558 return (PyObject *)v; |
|
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
559 } |
|
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
560 else |
|
bc50581b3d7c
More bug 460020: when F is a subclass of float, disable the unary plus
Tim Peters <tim.peters@gmail.com>
parents:
19865
diff
changeset
|
561 return PyFloat_FromDouble(v->ob_fval); |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
562 } |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
563 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
564 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
565 float_abs(PyFloatObject *v) |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
566 { |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
567 if (v->ob_fval < 0) |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
568 return float_neg(v); |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
569 else |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
570 return float_pos(v); |
| 6 | 571 } |
| 572 | |
| 239 | 573 static int |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
574 float_nonzero(PyFloatObject *v) |
| 239 | 575 { |
| 576 return v->ob_fval != 0.0; | |
| 577 } | |
| 578 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
579 static int |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
580 float_coerce(PyObject **pv, PyObject **pw) |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
581 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
582 if (PyInt_Check(*pw)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
583 long x = PyInt_AsLong(*pw); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
584 *pw = PyFloat_FromDouble((double)x); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
585 Py_INCREF(*pv); |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
586 return 0; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
587 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
588 else if (PyLong_Check(*pw)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
589 *pw = PyFloat_FromDouble(PyLong_AsDouble(*pw)); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
590 Py_INCREF(*pv); |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
591 return 0; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
592 } |
|
19976
da00188d5270
Add additional coercion support for "self subtypes" to int, long,
Guido van Rossum <guido@python.org>
parents:
19889
diff
changeset
|
593 else if (PyFloat_Check(*pw)) { |
|
da00188d5270
Add additional coercion support for "self subtypes" to int, long,
Guido van Rossum <guido@python.org>
parents:
19889
diff
changeset
|
594 Py_INCREF(*pv); |
|
da00188d5270
Add additional coercion support for "self subtypes" to int, long,
Guido van Rossum <guido@python.org>
parents:
19889
diff
changeset
|
595 Py_INCREF(*pw); |
|
da00188d5270
Add additional coercion support for "self subtypes" to int, long,
Guido van Rossum <guido@python.org>
parents:
19889
diff
changeset
|
596 return 0; |
|
da00188d5270
Add additional coercion support for "self subtypes" to int, long,
Guido van Rossum <guido@python.org>
parents:
19889
diff
changeset
|
597 } |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
598 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
|
599 } |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
600 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
601 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
602 float_int(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
603 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
604 double x = PyFloat_AsDouble(v); |
|
18838
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
605 double wholepart; /* integral portion of x, rounded toward 0 */ |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
606 long aslong; /* (long)wholepart */ |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
607 |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
608 (void)modf(x, &wholepart); |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
609 /* doubles may have more bits than longs, or vice versa; and casting |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
610 to long may yield gibberish in either case. What really matters |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
611 is whether converting back to double again reproduces what we |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
612 started with. */ |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
613 aslong = (long)wholepart; |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
614 if ((double)aslong == wholepart) |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
615 return PyInt_FromLong(aslong); |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
616 PyErr_SetString(PyExc_OverflowError, "float too large to convert"); |
|
a8575f358b9f
SF bug #444510: int() should guarantee truncation.
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
617 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
618 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
619 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
620 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
621 float_long(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
622 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
623 double x = PyFloat_AsDouble(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
624 return PyLong_FromDouble(x); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
625 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
626 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
627 static PyObject * |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
628 float_float(PyObject *v) |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
629 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
630 Py_INCREF(v); |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
631 return v; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
632 } |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
633 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
634 |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
635 staticforward PyObject * |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
636 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
637 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
638 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
639 float_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
640 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
641 PyObject *x = Py_False; /* Integer zero */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
642 static char *kwlist[] = {"x", 0}; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
643 |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
644 if (type != &PyFloat_Type) |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
645 return float_subtype_new(type, args, kwds); /* Wimp out */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
646 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
647 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
648 if (PyString_Check(x)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
649 return PyFloat_FromString(x, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
650 return PyNumber_Float(x); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
651 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
652 |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
653 /* Wimpy, slow approach to tp_new calls for subtypes of float: |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
654 first create a regular float from whatever arguments we got, |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
655 then allocate a subtype instance and initialize its ob_fval |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
656 from the regular float. The regular float is then thrown away. |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
657 */ |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
658 static PyObject * |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
659 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
660 { |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
661 PyObject *tmp, *new; |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
662 |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
663 assert(PyType_IsSubtype(type, &PyFloat_Type)); |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
664 tmp = float_new(&PyFloat_Type, args, kwds); |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
665 if (tmp == NULL) |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
666 return NULL; |
|
19889
733314fcfdaa
Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
19879
diff
changeset
|
667 assert(PyFloat_CheckExact(tmp)); |
|
19590
bf2c77840f1c
Fix typo: double semicolons.
Guido van Rossum <guido@python.org>
parents:
19552
diff
changeset
|
668 new = type->tp_alloc(type, 0); |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
669 if (new == NULL) |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
670 return NULL; |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
671 ((PyFloatObject *)new)->ob_fval = ((PyFloatObject *)tmp)->ob_fval; |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
672 Py_DECREF(tmp); |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
673 return new; |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
674 } |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
675 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
676 static char float_doc[] = |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
677 "float(x) -> floating point number\n\ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
678 \n\ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
679 Convert a string or number to a floating point number, if possible."; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
680 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
681 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
682 static PyNumberMethods float_as_number = { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
683 (binaryfunc)float_add, /*nb_add*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
684 (binaryfunc)float_sub, /*nb_subtract*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
685 (binaryfunc)float_mul, /*nb_multiply*/ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19590
diff
changeset
|
686 (binaryfunc)float_classic_div, /*nb_divide*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
687 (binaryfunc)float_rem, /*nb_remainder*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
688 (binaryfunc)float_divmod, /*nb_divmod*/ |
|
1775
17c80a952914
New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
689 (ternaryfunc)float_pow, /*nb_power*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
690 (unaryfunc)float_neg, /*nb_negative*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
691 (unaryfunc)float_pos, /*nb_positive*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
692 (unaryfunc)float_abs, /*nb_absolute*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
693 (inquiry)float_nonzero, /*nb_nonzero*/ |
|
405
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
694 0, /*nb_invert*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
695 0, /*nb_lshift*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
696 0, /*nb_rshift*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
697 0, /*nb_and*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
698 0, /*nb_xor*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
699 0, /*nb_or*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
700 (coercion)float_coerce, /*nb_coerce*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
701 (unaryfunc)float_int, /*nb_int*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
702 (unaryfunc)float_long, /*nb_long*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
703 (unaryfunc)float_float, /*nb_float*/ |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
704 0, /* nb_oct */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
705 0, /* nb_hex */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
706 0, /* nb_inplace_add */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
707 0, /* nb_inplace_subtract */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
708 0, /* nb_inplace_multiply */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
709 0, /* nb_inplace_divide */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
710 0, /* nb_inplace_remainder */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
711 0, /* nb_inplace_power */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
712 0, /* nb_inplace_lshift */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
713 0, /* nb_inplace_rshift */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
714 0, /* nb_inplace_and */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
715 0, /* nb_inplace_xor */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
716 0, /* nb_inplace_or */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
717 float_int_div, /* nb_floor_divide */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
718 float_div, /* nb_true_divide */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
719 0, /* nb_inplace_floor_divide */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
720 0, /* nb_inplace_true_divide */ |
| 6 | 721 }; |
| 722 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
723 PyTypeObject PyFloat_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
724 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 725 0, |
| 726 "float", | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
727 sizeof(PyFloatObject), |
| 6 | 728 0, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
729 (destructor)float_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
730 (printfunc)float_print, /* tp_print */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
731 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
732 0, /* tp_setattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
733 (cmpfunc)float_compare, /* tp_compare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
734 (reprfunc)float_repr, /* tp_repr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
735 &float_as_number, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
736 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
737 0, /* tp_as_mapping */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
738 (hashfunc)float_hash, /* tp_hash */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
739 0, /* tp_call */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
740 (reprfunc)float_str, /* tp_str */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
741 PyObject_GenericGetAttr, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
742 0, /* tp_setattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
743 0, /* tp_as_buffer */ |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
744 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES | |
|
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
745 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
746 float_doc, /* tp_doc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
747 0, /* tp_traverse */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
748 0, /* tp_clear */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
749 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
750 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
751 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
752 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
753 0, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
754 0, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
755 0, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
756 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
757 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
758 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
759 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
760 0, /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
761 0, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
762 0, /* tp_alloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18838
diff
changeset
|
763 float_new, /* tp_new */ |
| 6 | 764 }; |
|
5936
80d24364b932
Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents:
5504
diff
changeset
|
765 |
|
80d24364b932
Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents:
5504
diff
changeset
|
766 void |
|
13454
fcc75a3748f5
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
767 PyFloat_Fini(void) |
|
5936
80d24364b932
Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents:
5504
diff
changeset
|
768 { |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
769 PyFloatObject *p; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
770 PyFloatBlock *list, *next; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
771 int i; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
772 int bc, bf; /* block count, number of freed blocks */ |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
773 int frem, fsum; /* remaining unfreed floats per block, total */ |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
774 |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
775 bc = 0; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
776 bf = 0; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
777 fsum = 0; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
778 list = block_list; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
779 block_list = NULL; |
|
10432
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
780 free_list = NULL; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
781 while (list != NULL) { |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
782 bc++; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
783 frem = 0; |
|
10432
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
784 for (i = 0, p = &list->objects[0]; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
785 i < N_FLOATOBJECTS; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
786 i++, p++) { |
|
19865
f2a3009b528e
Replace a few places where X->ob_type was compared to &PyXXX_Type with
Guido van Rossum <guido@python.org>
parents:
19753
diff
changeset
|
787 if (PyFloat_CheckExact(p) && p->ob_refcnt != 0) |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
788 frem++; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
789 } |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
790 next = list->next; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
791 if (frem) { |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
792 list->next = block_list; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
793 block_list = list; |
|
10432
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
794 for (i = 0, p = &list->objects[0]; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
795 i < N_FLOATOBJECTS; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
796 i++, p++) { |
|
19865
f2a3009b528e
Replace a few places where X->ob_type was compared to &PyXXX_Type with
Guido van Rossum <guido@python.org>
parents:
19753
diff
changeset
|
797 if (!PyFloat_CheckExact(p) || |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
798 p->ob_refcnt == 0) { |
|
10432
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
799 p->ob_type = (struct _typeobject *) |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
800 free_list; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
801 free_list = p; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
802 } |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
803 } |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
804 } |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
805 else { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12248
diff
changeset
|
806 PyMem_FREE(list); /* XXX PyObject_FREE ??? */ |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
807 bf++; |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
808 } |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
809 fsum += frem; |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
810 list = next; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
811 } |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
812 if (!Py_VerboseFlag) |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
813 return; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
814 fprintf(stderr, "# cleanup floats"); |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
815 if (!fsum) { |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
816 fprintf(stderr, "\n"); |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
817 } |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
818 else { |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
819 fprintf(stderr, |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
820 ": %d unfreed float%s in %d out of %d block%s\n", |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
821 fsum, fsum == 1 ? "" : "s", |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
822 bc - bf, bc, bc == 1 ? "" : "s"); |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
823 } |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
824 if (Py_VerboseFlag > 1) { |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
825 list = block_list; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
826 while (list != NULL) { |
|
10432
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
827 for (i = 0, p = &list->objects[0]; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
828 i < N_FLOATOBJECTS; |
|
1cc5d20d2ed8
Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
Guido van Rossum <guido@python.org>
parents:
10391
diff
changeset
|
829 i++, p++) { |
|
19865
f2a3009b528e
Replace a few places where X->ob_type was compared to &PyXXX_Type with
Guido van Rossum <guido@python.org>
parents:
19753
diff
changeset
|
830 if (PyFloat_CheckExact(p) && |
|
19552
6c30d20d27f2
Make int, long and float subclassable.
Guido van Rossum <guido@python.org>
parents:
19457
diff
changeset
|
831 p->ob_refcnt != 0) { |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
832 char buf[100]; |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
833 PyFloat_AsString(buf, p); |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
834 fprintf(stderr, |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13141
diff
changeset
|
835 "# <float at %p, refcnt=%d, val=%s>\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13141
diff
changeset
|
836 p, p->ob_refcnt, buf); |
|
10391
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
837 } |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
838 } |
|
7b810aa35b5c
Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents:
10382
diff
changeset
|
839 list = list->next; |
|
10382
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
840 } |
|
e2a08a81e56f
OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents:
10375
diff
changeset
|
841 } |
|
5936
80d24364b932
Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents:
5504
diff
changeset
|
842 } |
