annotate Objects/floatobject.c @ 11518:cc412dfd79f7 legacy-trunk

New examples by Tony Ingraldi, using dns-lookup in stead of the funny interslip module.
author Jack Jansen <jack.jansen@cwi.nl>
date Fri, 03 Dec 1999 15:15:28 +0000
parents aca7b5eaf5e8
children cf7a0f1b7b48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
1 /***********************************************************
2059
866c81068dbd Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2053
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
866c81068dbd Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2053
diff changeset
3 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
8 documentation for any purpose and without fee is hereby granted,
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
10 both that copyright notice and this permission notice appear in
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
15 permission.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4282
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
29
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
30 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 91
diff changeset
31
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Float object implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
34 /* XXX There should be overflow checks here, but it's hard to check
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
35 for any kind of float exception without losing portability. */
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
36
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
37 #include "Python.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 60
diff changeset
39 #include <ctype.h>
2433
6cbd2830b5a2 for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents: 2327
diff changeset
40 #include "mymath.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
1271
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
42 #ifdef i860
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
43 /* Cray APP has bogus definition of HUGE_VAL in <math.h> */
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
44 #undef HUGE_VAL
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
45 #endif
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
46
3704
17030515f623 Different logic for defining CHECK(); 16-bit MSC specific define.
Guido van Rossum <guido@python.org>
parents: 3608
diff changeset
47 #if defined(HUGE_VAL) && !defined(CHECK)
496
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
48 #define CHECK(x) if (errno != 0) ; \
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
49 else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
50 else errno = ERANGE
3704
17030515f623 Different logic for defining CHECK(); 16-bit MSC specific define.
Guido van Rossum <guido@python.org>
parents: 3608
diff changeset
51 #endif
17030515f623 Different logic for defining CHECK(); 16-bit MSC specific define.
Guido van Rossum <guido@python.org>
parents: 3608
diff changeset
52
17030515f623 Different logic for defining CHECK(); 16-bit MSC specific define.
Guido van Rossum <guido@python.org>
parents: 3608
diff changeset
53 #ifndef CHECK
496
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
54 #define CHECK(x) /* Don't know how to check */
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
55 #endif
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
56
1908
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
57 #ifdef HAVE_LIMITS_H
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
58 #include <limits.h>
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
59 #endif
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
60
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
61 #ifndef LONG_MAX
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
62 #define LONG_MAX 0X7FFFFFFFL
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
63 #endif
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
64
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
65 #ifndef LONG_MIN
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
66 #define LONG_MIN (-LONG_MAX-1)
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
67 #endif
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
68
2327
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
69 #ifdef __NeXT__
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
70 #ifdef __sparc__
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
71 /*
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
72 * This works around a bug in the NS/Sparc 3.3 pre-release
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
73 * limits.h header file.
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
74 * 10-Feb-1995 bwarsaw@cnri.reston.va.us
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
75 */
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
76 #undef LONG_MIN
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
77 #define LONG_MIN (-LONG_MAX-1)
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
78 #endif
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
79 #endif
43f9e7549c70 NeXT/Sparc 3.3 fix
Guido van Rossum <guido@python.org>
parents: 2308
diff changeset
80
2433
6cbd2830b5a2 for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents: 2327
diff changeset
81 #if !defined(__STDC__) && !defined(macintosh)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
82 extern double fmod Py_PROTO((double, double));
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
83 extern double pow Py_PROTO((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
84 #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
85
6537
25505e563b37 Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents: 5936
diff changeset
86 #ifdef sun
25505e563b37 Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents: 5936
diff changeset
87 /* 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
88 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
89 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
90 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
91 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
92 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
93 };
25505e563b37 Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents: 5936
diff changeset
94 #endif
25505e563b37 Hack suggested by Matthias Klose to pull in all relevant entry points
Guido van Rossum <guido@python.org>
parents: 5936
diff changeset
95
5504
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
96 /* 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
97 #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
98 #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
99 #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
100
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
101 #define PyMem_MALLOC malloc
e2a08a81e56f OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents: 10375
diff changeset
102 #define PyMem_FREE free
5504
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
103
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
104 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
105 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
106 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
107 };
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
108
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
109 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
110
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
111 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
112 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
113
5504
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
114 static PyFloatObject *
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
115 fill_free_list()
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
116 {
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
117 PyFloatObject *p, *q;
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
118 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
119 if (p == NULL)
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
120 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
121 ((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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 }
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
130
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
131 PyObject *
2433
6cbd2830b5a2 for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents: 2327
diff changeset
132 #ifdef __SC__
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
133 PyFloat_FromDouble(double fval)
2433
6cbd2830b5a2 for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents: 2327
diff changeset
134 #else
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
135 PyFloat_FromDouble(fval)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 double fval;
2433
6cbd2830b5a2 for MPW __SC__ compiler
Guido van Rossum <guido@python.org>
parents: 2327
diff changeset
137 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 {
5504
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
139 register PyFloatObject *op;
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
140 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
141 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
142 return NULL;
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
143 }
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
144 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
145 free_list = (PyFloatObject *)op->ob_type;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
146 op->ob_type = &PyFloat_Type;
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
147 op->ob_fval = fval;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
148 _Py_NewReference(op);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
149 return (PyObject *) op;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
152 PyObject *
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
153 PyFloat_FromString(v, pend)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
154 PyObject *v;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
155 char **pend;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
156 {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
157 extern double strtod Py_PROTO((const char *, char **));
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
158 char *s, *last, *end;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
159 double x;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
160 char buffer[256]; /* For errors */
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
161
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
162 if (!PyString_Check(v))
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
163 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
164 s = PyString_AS_STRING(v);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
165
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
166 last = s + PyString_GET_SIZE(v);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
167 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
168 s++;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
169 if (s[0] == '\0') {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
170 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
171 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
172 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
173 errno = 0;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
174 PyFPE_START_PROTECT("PyFloat_FromString", return 0)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
175 x = strtod(s, &end);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
176 PyFPE_END_PROTECT(x)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
177 /* Believe it or not, Solaris 2.6 can move end *beyond* the null
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
178 byte at the end of the string, when the input is inf(inity) */
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
179 if (end > last)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
180 end = last;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
181 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
182 end++;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
183 if (*end != '\0') {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
184 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
185 PyErr_SetString(PyExc_ValueError, buffer);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
186 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
187 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
188 else if (end != PyString_AS_STRING(v) + PyString_GET_SIZE(v)) {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
189 PyErr_SetString(PyExc_ValueError,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
190 "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
191 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
192 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
193 else if (errno != 0) {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
194 sprintf(buffer, "float() literal too large: %.200s", s);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
195 PyErr_SetString(PyExc_ValueError, buffer);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
196 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
197 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
198 if (pend)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
199 *pend = end;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
200 return PyFloat_FromDouble(x);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
201 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 10833
diff changeset
202
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
203 static void
745
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
204 float_dealloc(op)
5504
c88b9b868995 Faster floating point allocator, same idea as the int allocator.
Guido van Rossum <guido@python.org>
parents: 5396
diff changeset
205 PyFloatObject *op;
745
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
206 {
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
207 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
208 free_list = op;
745
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
209 }
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
210
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 double
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
212 PyFloat_AsDouble(op)
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
213 PyObject *op;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
215 PyNumberMethods *nb;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
216 PyFloatObject *fo;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
217 double val;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
218
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
219 if (op && PyFloat_Check(op))
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
220 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
221
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
222 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
223 nb->nb_float == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
224 PyErr_BadArgument();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 return -1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
227
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
228 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
229 if (fo == NULL)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
230 return -1;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
231 if (!PyFloat_Check(fo)) {
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
232 PyErr_SetString(PyExc_TypeError,
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
233 "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
234 return -1;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
235 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
236
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
237 val = PyFloat_AS_DOUBLE(fo);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
238 Py_DECREF(fo);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
239
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
240 return val;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 /* Methods */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
268
0fe2471166f0 Export float_buf_repr() interface, for marshalling of floats.
Guido van Rossum <guido@python.org>
parents: 249
diff changeset
245 void
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
246 PyFloat_AsString(buf, v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 char *buf;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
248 PyFloatObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 register char *cp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 /* Subroutine for float_repr and float_print.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 We want float numbers to be recognizable as such,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 i.e., they should contain a decimal point or an exponent.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 However, %g may print the number as an integer;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 in such cases, we append ".0" to the string. */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 sprintf(buf, "%.12g", v->ob_fval);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 cp = buf;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 if (*cp == '-')
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 cp++;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 for (; *cp != '\0'; cp++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 /* Any non-digit means it's not an integer;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 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
263 if (!isdigit(Py_CHARMASK(*cp)))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 break;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 if (*cp == '\0') {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 *cp++ = '.';
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 *cp++ = '0';
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 *cp++ = '\0';
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272
745
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
273 /* ARGSUSED */
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 268
diff changeset
274 static int
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 float_print(v, fp, flags)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
276 PyFloatObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 FILE *fp;
745
c7b23cc8cded answer lint's complaints
Guido van Rossum <guido@python.org>
parents: 632
diff changeset
278 int flags; /* Not used but required by interface */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 char buf[100];
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
281 PyFloat_AsString(buf, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 fputs(buf, fp);
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 268
diff changeset
283 return 0;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
286 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 float_repr(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
288 PyFloatObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 char buf[100];
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
291 PyFloat_AsString(buf, v);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
292 return PyString_FromString(buf);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 static int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 float_compare(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
297 PyFloatObject *v, *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 double i = v->ob_fval;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 double j = w->ob_fval;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 return (i < j) ? -1 : (i > j) ? 1 : 0;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
304 static long
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
305 float_hash(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
306 PyFloatObject *v;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
307 {
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
308 double intpart, fractpart;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
309 int expo;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
310 long x;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
311 /* This is designed so that Python numbers with the same
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
312 value hash to the same value, otherwise comparisons
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
313 of mapping keys will turn out weird */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
314
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
315 #ifdef MPW /* MPW C modf expects pointer to extended as second argument */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
316 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
317 extended e;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
318 fractpart = modf(v->ob_fval, &e);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
319 intpart = e;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
320 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
321 #else
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
322 fractpart = modf(v->ob_fval, &intpart);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
323 #endif
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
324
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
325 if (fractpart == 0.0) {
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
326 if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
327 /* Convert to long int and use its hash... */
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
328 PyObject *w = PyLong_FromDouble(v->ob_fval);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
329 if (w == NULL)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
330 return -1;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
331 x = PyObject_Hash(w);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
332 Py_DECREF(w);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
333 return x;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
334 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
335 x = (long)intpart;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
336 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
337 else {
4933
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
338 /* Note -- if you change this code, also change the copy
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
339 in complexobject.c */
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
340 long hipart;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
341 fractpart = frexp(fractpart, &expo);
4933
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
342 fractpart = fractpart * 2147483648.0; /* 2**31 */
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
343 hipart = (long)fractpart; /* Take the top 32 bits */
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
344 fractpart = (fractpart - (double)hipart) * 2147483648.0;
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
345 /* Get the next 32 bits */
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
346 x = hipart + (long)fractpart + (long)intpart + (expo << 15);
b56bc25aec85 New, better hash for floating point and complex
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
347 /* Combine everything */
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 if (x == -1)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
350 x = -2;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
351 return x;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
352 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
353
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
354 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 float_add(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
356 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
357 PyFloatObject *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 {
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
359 double result;
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
360 PyFPE_START_PROTECT("add", return 0)
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
361 result = v->ob_fval + w->ob_fval;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
362 PyFPE_END_PROTECT(result)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
363 return PyFloat_FromDouble(result);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
366 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 float_sub(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
368 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
369 PyFloatObject *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 {
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
371 double result;
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
372 PyFPE_START_PROTECT("subtract", return 0)
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
373 result = v->ob_fval - w->ob_fval;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
374 PyFPE_END_PROTECT(result)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
375 return PyFloat_FromDouble(result);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
378 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 float_mul(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
380 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
381 PyFloatObject *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 {
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
383 double result;
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
384
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
385 PyFPE_START_PROTECT("multiply", return 0)
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
386 result = v->ob_fval * w->ob_fval;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
387 PyFPE_END_PROTECT(result)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
388 return PyFloat_FromDouble(result);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
391 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 float_div(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
393 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
394 PyFloatObject *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 {
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
396 double result;
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
397 if (w->ob_fval == 0) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
398 PyErr_SetString(PyExc_ZeroDivisionError, "float division");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 }
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
401 PyFPE_START_PROTECT("divide", return 0)
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
402 result = v->ob_fval / w->ob_fval;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
403 PyFPE_END_PROTECT(result)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
404 return PyFloat_FromDouble(result);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
407 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 float_rem(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
409 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
410 PyFloatObject *w;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 {
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
412 double vx, wx;
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
413 double mod;
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
414 wx = w->ob_fval;
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
415 if (wx == 0.0) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
416 PyErr_SetString(PyExc_ZeroDivisionError, "float modulo");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 }
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
419 PyFPE_START_PROTECT("modulo", return 0)
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
420 vx = v->ob_fval;
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
421 mod = fmod(vx, wx);
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
422 /* note: checking mod*wx < 0 is incorrect -- underflows to
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
423 0 if wx < sqrt(smallest nonzero double) */
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
424 if (mod && ((wx < 0) != (mod < 0))) {
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
425 mod += wx;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 }
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
427 PyFPE_END_PROTECT(mod)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
428 return PyFloat_FromDouble(mod);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
430
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
431 static PyObject *
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
432 float_divmod(v, w)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
433 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
434 PyFloatObject *w;
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
435 {
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
436 double vx, wx;
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
437 double div, mod, floordiv;
632
0c1938f2e0c0 Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents: 496
diff changeset
438 wx = w->ob_fval;
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
439 if (wx == 0.0) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
440 PyErr_SetString(PyExc_ZeroDivisionError, "float divmod()");
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
441 return NULL;
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
442 }
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
443 PyFPE_START_PROTECT("divmod", return 0)
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
444 vx = v->ob_fval;
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
445 mod = fmod(vx, wx);
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
446 /* fmod is typically exact, so vx-mod is *mathemtically* an
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
447 exact multiple of wx. But this is fp arithmetic, and fp
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
448 vx - mod is an approximation; the result is that div may
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
449 not be an exact integral value after the division, although
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
450 it will always be very close to one.
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
451 */
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
452 div = (vx - mod) / wx;
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
453 /* note: checking mod*wx < 0 is incorrect -- underflows to
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
454 0 if wx < sqrt(smallest nonzero double) */
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
455 if (mod && ((wx < 0) != (mod < 0))) {
391
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
456 mod += wx;
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
457 div -= 1.0;
caf8466dcc9c Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
458 }
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
459 /* snap quotient to nearest integral value */
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
460 floordiv = floor(div);
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
461 if (div - floordiv > 0.5)
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
462 floordiv += 1.0;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
463 PyFPE_END_PROTECT(div)
10833
135c1ec9636c Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 10432
diff changeset
464 return Py_BuildValue("(dd)", floordiv, mod);
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
465 }
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
466
3608
8573e65fa948 make some things static
Guido van Rossum <guido@python.org>
parents: 3329
diff changeset
467 static double powu(x, n)
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
468 double x;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
469 long n;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
470 {
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
471 double r = 1.;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
472 double p = x;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
473 long mask = 1;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
474 while (mask > 0 && n >= mask) {
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
475 if (n & mask)
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
476 r *= p;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
477 mask <<= 1;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
478 p *= p;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
479 }
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
480 return r;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
481 }
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
482
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
483 static PyObject *
1775
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
484 float_pow(v, w, z)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
485 PyFloatObject *v;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
486 PyObject *w;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
487 PyFloatObject *z;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 double iv, iw, ix;
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
490 long intw;
1775
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
491 /* XXX Doesn't handle overflows if z!=None yet; it may never do so :(
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
492 * The z parameter is really only going to be useful for integers and
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
493 * long integers. Maybe something clever with logarithms could be done.
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
494 * [AMK]
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
495 */
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
496 iv = v->ob_fval;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
497 iw = ((PyFloatObject *)w)->ob_fval;
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
498 intw = (long)iw;
4007
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
499 if (iw == intw && -10000 < intw && intw < 10000) {
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
500 /* Sort out special cases here instead of relying on pow() */
3984
0613f17dcfd8 Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents: 3704
diff changeset
501 if (intw == 0) { /* x**0 is 1, even 0**0 */
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
502 PyFPE_START_PROTECT("pow", return 0)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
503 if ((PyObject *)z!=Py_None) {
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
504 ix=fmod(1.0, z->ob_fval);
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
505 if (ix!=0 && z->ob_fval<0) ix+=z->ob_fval;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
506 }
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
507 else ix=1.0;
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
508 PyFPE_END_PROTECT(ix)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
509 return PyFloat_FromDouble(ix);
249
bab1f5494b8e Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents: 239
diff changeset
510 }
3984
0613f17dcfd8 Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents: 3704
diff changeset
511 errno = 0;
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
512 PyFPE_START_PROTECT("pow", return 0)
4007
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
513 if (intw > 0)
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
514 ix = powu(iv, intw);
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
515 else
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
516 ix = 1./powu(iv, -intw);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
517 PyFPE_END_PROTECT(ix)
3984
0613f17dcfd8 Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents: 3704
diff changeset
518 }
0613f17dcfd8 Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents: 3704
diff changeset
519 else {
0613f17dcfd8 Correct wrong calculation of pow(0.0, 0.0, negative_number)
Guido van Rossum <guido@python.org>
parents: 3704
diff changeset
520 /* Sort out special cases here instead of relying on pow() */
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
521 if (iv == 0.0) {
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
522 if (iw < 0.0) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
523 PyErr_SetString(PyExc_ValueError,
4007
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
524 "0.0 to a negative power");
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
525 return NULL;
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
526 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
527 return PyFloat_FromDouble(0.0);
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
528 }
4007
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
529 if (iv < 0.0) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
530 PyErr_SetString(PyExc_ValueError,
4007
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
531 "negative number to a float power");
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
532 return NULL;
1a0aa986f6fa Test for negative # to the nonintegral float power here.
Guido van Rossum <guido@python.org>
parents: 3984
diff changeset
533 }
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
534 errno = 0;
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
535 PyFPE_START_PROTECT("pow", return 0)
3329
67d347c32fff better power implementation
Guido van Rossum <guido@python.org>
parents: 2433
diff changeset
536 ix = pow(iv, iw);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
537 PyFPE_END_PROTECT(ix)
249
bab1f5494b8e Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents: 239
diff changeset
538 }
496
0ac392b7f76e Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents: 470
diff changeset
539 CHECK(ix);
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
540 if (errno != 0) {
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
541 /* 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
542 PyErr_SetFromErrno(PyExc_OverflowError);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 return NULL;
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
544 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
545 if ((PyObject *)z!=Py_None) {
5118
002865af55e5 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4933
diff changeset
546 PyFPE_START_PROTECT("pow", return 0)
1775
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
547 ix=fmod(ix, z->ob_fval); /* XXX To Be Rewritten */
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
548 if ( ix!=0 &&
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
549 ((iv<0 && z->ob_fval>0) || (iv>0 && z->ob_fval<0) )) {
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
550 ix+=z->ob_fval;
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
551 }
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5118
diff changeset
552 PyFPE_END_PROTECT(ix)
1775
17c80a952914 New patches by Andrew to fix various problems
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
553 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
554 return PyFloat_FromDouble(ix);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
557 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 float_neg(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
559 PyFloatObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
560 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
561 return PyFloat_FromDouble(-v->ob_fval);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
562 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
563
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
564 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 float_pos(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
566 PyFloatObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
568 Py_INCREF(v);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
569 return (PyObject *)v;
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
570 }
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
571
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
572 static PyObject *
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
573 float_abs(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
574 PyFloatObject *v;
227
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
575 {
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
576 if (v->ob_fval < 0)
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
577 return float_neg(v);
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
578 else
7ec6058b539b Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
579 return float_pos(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
581
239
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
582 static int
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
583 float_nonzero(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
584 PyFloatObject *v;
239
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
585 {
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
586 return v->ob_fval != 0.0;
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
587 }
fda973f2a512 Added nonzero test
Guido van Rossum <guido@python.org>
parents: 227
diff changeset
588
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
589 static int
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
590 float_coerce(pv, pw)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
591 PyObject **pv;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
592 PyObject **pw;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
593 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
594 if (PyInt_Check(*pw)) {
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
595 long x = PyInt_AsLong(*pw);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
596 *pw = PyFloat_FromDouble((double)x);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
597 Py_INCREF(*pv);
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
598 return 0;
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
599 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
600 else if (PyLong_Check(*pw)) {
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
601 *pw = PyFloat_FromDouble(PyLong_AsDouble(*pw));
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
602 Py_INCREF(*pv);
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
603 return 0;
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
604 }
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
605 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
606 }
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
607
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
608 static PyObject *
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
609 float_int(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
610 PyObject *v;
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
611 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
612 double x = PyFloat_AsDouble(v);
1908
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
613 if (x < 0 ? (x = ceil(x)) < (double)LONG_MIN
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
614 : (x = floor(x)) > (double)LONG_MAX) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
615 PyErr_SetString(PyExc_OverflowError,
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
616 "float too large to convert");
1908
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
617 return NULL;
0437738279a8 * Include/classobject.h, Objects/classobject.c, Python/ceval.c:
Guido van Rossum <guido@python.org>
parents: 1775
diff changeset
618 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
619 return PyInt_FromLong((long)x);
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
620 }
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
621
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
622 static PyObject *
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
623 float_long(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
624 PyObject *v;
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
625 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
626 double x = PyFloat_AsDouble(v);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
627 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
628 }
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 static PyObject *
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
631 float_float(v)
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
632 PyObject *v;
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
633 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
634 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
635 return v;
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
636 }
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
637
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
638
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
639 static PyNumberMethods float_as_number = {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
640 (binaryfunc)float_add, /*nb_add*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
641 (binaryfunc)float_sub, /*nb_subtract*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
642 (binaryfunc)float_mul, /*nb_multiply*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
643 (binaryfunc)float_div, /*nb_divide*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
644 (binaryfunc)float_rem, /*nb_remainder*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
645 (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
646 (ternaryfunc)float_pow, /*nb_power*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
647 (unaryfunc)float_neg, /*nb_negative*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
648 (unaryfunc)float_pos, /*nb_positive*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
649 (unaryfunc)float_abs, /*nb_absolute*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
650 (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
651 0, /*nb_invert*/
d3d328680328 Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 391
diff changeset
652 0, /*nb_lshift*/
d3d328680328 Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 391
diff changeset
653 0, /*nb_rshift*/
d3d328680328 Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 391
diff changeset
654 0, /*nb_and*/
d3d328680328 Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 391
diff changeset
655 0, /*nb_xor*/
d3d328680328 Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 391
diff changeset
656 0, /*nb_or*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
657 (coercion)float_coerce, /*nb_coerce*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
658 (unaryfunc)float_int, /*nb_int*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
659 (unaryfunc)float_long, /*nb_long*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
660 (unaryfunc)float_float, /*nb_float*/
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
661 0, /*nb_oct*/
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
662 0, /*nb_hex*/
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
664
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
665 PyTypeObject PyFloat_Type = {
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
666 PyObject_HEAD_INIT(&PyType_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 0,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
668 "float",
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
669 sizeof(PyFloatObject),
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
670 0,
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
671 (destructor)float_dealloc, /*tp_dealloc*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
672 (printfunc)float_print, /*tp_print*/
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
673 0, /*tp_getattr*/
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
674 0, /*tp_setattr*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
675 (cmpfunc)float_compare, /*tp_compare*/
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
676 (reprfunc)float_repr, /*tp_repr*/
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 &float_as_number, /*tp_as_number*/
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 0, /*tp_as_sequence*/
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
679 0, /*tp_as_mapping*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
680 (hashfunc)float_hash, /*tp_hash*/
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 };
5936
80d24364b932 Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents: 5504
diff changeset
682
80d24364b932 Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents: 5504
diff changeset
683 void
80d24364b932 Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents: 5504
diff changeset
684 PyFloat_Fini()
80d24364b932 Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents: 5504
diff changeset
685 {
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
686 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
687 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
688 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
689 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
690 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
691
e2a08a81e56f OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents: 10375
diff changeset
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700 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
701 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
702 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
703 i++, 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
704 if (PyFloat_Check(p) && p->ob_refcnt != 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
705 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
706 }
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
707 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
708 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
709 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
710 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
711 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
712 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
713 i++, 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
714 if (!PyFloat_Check(p) || p->ob_refcnt == 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
715 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
716 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
717 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
718 }
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
719 }
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
720 }
e2a08a81e56f OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents: 10375
diff changeset
721 else {
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
722 PyMem_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
723 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
724 }
e2a08a81e56f OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents: 10375
diff changeset
725 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
726 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
727 }
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
728 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
729 return;
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
730 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
731 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
732 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
733 }
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
734 else {
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
735 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
736 ": %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
737 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
738 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
739 }
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
740 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
741 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
742 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
743 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
744 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
745 i++, p++) {
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
746 if (PyFloat_Check(p) && p->ob_refcnt != 0) {
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
747 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
748 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
749 fprintf(stderr,
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
750 "# <float at %lx, refcnt=%d, val=%s>\n",
10391
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
751 p, p->ob_refcnt, buf);
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
752 }
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
753 }
7b810aa35b5c Vladimir has restructured his code somewhat so that the blocks are now
Guido van Rossum <guido@python.org>
parents: 10382
diff changeset
754 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
755 }
e2a08a81e56f OK, try again. Vladimir gave me a fix for the alignment bus error,
Guido van Rossum <guido@python.org>
parents: 10375
diff changeset
756 }
5936
80d24364b932 Added _Fini() routines to free up some memory
Guido van Rossum <guido@python.org>
parents: 5504
diff changeset
757 }