Mercurial > cpython-lru_cache-weakref
annotate Modules/mathmodule.c @ 3930:52c19ee83a6b legacy-trunk
Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Fri, 02 Aug 1996 15:16:16 +0000 |
| parents | 2da12c9d714f |
| children | fc505f02ad8a |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Math module -- standard C math library functions, pi and e */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 |
| 92 | 29 #include <errno.h> |
| 30 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
31 #define getdoublearg(v, a) getargs(v, "d", a) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
32 #define get2doublearg(v, a, b) getargs(v, "(dd)", a, b) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
33 |
| 2455 | 34 #include "mymath.h" |
| 86 | 35 |
| 3597 | 36 #ifndef _MSC_VER |
|
2125
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
37 #ifndef __STDC__ |
|
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
38 extern double fmod PROTO((double, double)); |
|
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
39 extern double frexp PROTO((double, int *)); |
|
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
40 extern double ldexp PROTO((double, int)); |
|
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
41 extern double modf PROTO((double, double *)); |
| 3597 | 42 #endif /* __STDC__ */ |
| 43 #endif /* _MSC_VER */ | |
| 44 | |
|
2125
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
45 |
|
3881
2da12c9d714f
Don't make an exception for NeXT (BBUM says it's no longer needed).
Guido van Rossum <guido@python.org>
parents:
3597
diff
changeset
|
46 #if defined(HAVE_HYPOT) |
|
2125
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
47 extern double hypot PROTO((double, double)); |
|
3339
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
48 #else |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
49 double hypot(x,y) |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
50 double x; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
51 double y; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
52 { |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
53 double yx; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
54 |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
55 x = fabs(x); |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
56 y = fabs(y); |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
57 if (x < y) { |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
58 double temp = x; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
59 x = y; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
60 y = temp; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
61 } |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
62 if (x == 0.) |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
63 return 0.; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
64 else { |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
65 yx = y/x; |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
66 return x*sqrt(1.+yx*yx); |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
67 } |
|
16cb0473224c
added default hypot() implementation
Guido van Rossum <guido@python.org>
parents:
2734
diff
changeset
|
68 } |
|
2125
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
69 #endif |
|
bd061dc30842
rearrange declarations somewhat
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
70 |
|
1271
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
71 #ifdef i860 |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
72 /* 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:
1252
diff
changeset
|
73 #undef HUGE_VAL |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
74 #endif |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
75 |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
76 #ifdef HUGE_VAL |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
77 #define CHECK(x) if (errno != 0) ; \ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
78 else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
79 else errno = ERANGE |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
80 #else |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
81 #define CHECK(x) /* Don't know how to check */ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
82 #endif |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
83 |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
84 static object * |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
85 math_error() |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
86 { |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
87 if (errno == EDOM) |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
88 err_setstr(ValueError, "math domain error"); |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
89 else if (errno == ERANGE) |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
90 err_setstr(OverflowError, "math range error"); |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
91 else |
|
679
6a60342c3107
Get rid of RuntimeError.
Guido van Rossum <guido@python.org>
parents:
591
diff
changeset
|
92 err_errno(ValueError); /* Unexpected math error */ |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
93 return NULL; |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
94 } |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
95 |
| 6 | 96 static object * |
| 97 math_1(args, func) | |
| 98 object *args; | |
| 99 double (*func) FPROTO((double)); | |
| 100 { | |
| 101 double x; | |
| 102 if (!getdoublearg(args, &x)) | |
| 103 return NULL; | |
| 104 errno = 0; | |
| 105 x = (*func)(x); | |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
106 CHECK(x); |
| 6 | 107 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
108 return math_error(); |
| 6 | 109 else |
| 110 return newfloatobject(x); | |
| 111 } | |
| 112 | |
| 113 static object * | |
| 114 math_2(args, func) | |
| 115 object *args; | |
| 116 double (*func) FPROTO((double, double)); | |
| 117 { | |
| 118 double x, y; | |
| 119 if (!get2doublearg(args, &x, &y)) | |
| 120 return NULL; | |
| 121 errno = 0; | |
| 122 x = (*func)(x, y); | |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
123 CHECK(x); |
| 6 | 124 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
125 return math_error(); |
| 6 | 126 else |
| 127 return newfloatobject(x); | |
| 128 } | |
| 129 | |
| 130 #define FUNC1(stubname, func) \ | |
| 131 static object * stubname(self, args) object *self, *args; { \ | |
| 132 return math_1(args, func); \ | |
| 133 } | |
| 134 | |
| 135 #define FUNC2(stubname, func) \ | |
| 136 static object * stubname(self, args) object *self, *args; { \ | |
| 137 return math_2(args, func); \ | |
| 138 } | |
| 139 | |
| 140 FUNC1(math_acos, acos) | |
| 141 FUNC1(math_asin, asin) | |
| 142 FUNC1(math_atan, atan) | |
| 143 FUNC2(math_atan2, atan2) | |
| 144 FUNC1(math_ceil, ceil) | |
| 145 FUNC1(math_cos, cos) | |
| 146 FUNC1(math_cosh, cosh) | |
| 147 FUNC1(math_exp, exp) | |
| 148 FUNC1(math_fabs, fabs) | |
| 149 FUNC1(math_floor, floor) | |
| 150 FUNC2(math_fmod, fmod) | |
| 1986 | 151 FUNC2(math_hypot, hypot) |
| 6 | 152 FUNC1(math_log, log) |
| 153 FUNC1(math_log10, log10) | |
|
320
26426c42a162
Add some err_errno calls that were missing
Guido van Rossum <guido@python.org>
parents:
289
diff
changeset
|
154 #ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */ |
|
289
c4c278c56e90
Apparently MPW has power() instead of pow().
Guido van Rossum <guido@python.org>
parents:
168
diff
changeset
|
155 FUNC2(math_pow, power) |
|
c4c278c56e90
Apparently MPW has power() instead of pow().
Guido van Rossum <guido@python.org>
parents:
168
diff
changeset
|
156 #else |
| 6 | 157 FUNC2(math_pow, pow) |
|
289
c4c278c56e90
Apparently MPW has power() instead of pow().
Guido van Rossum <guido@python.org>
parents:
168
diff
changeset
|
158 #endif |
| 6 | 159 FUNC1(math_sin, sin) |
| 160 FUNC1(math_sinh, sinh) | |
| 161 FUNC1(math_sqrt, sqrt) | |
| 162 FUNC1(math_tan, tan) | |
| 163 FUNC1(math_tanh, tanh) | |
| 164 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
165 |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
166 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
167 math_frexp(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
168 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
169 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
170 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
171 double x; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
172 int i; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
173 if (!getdoublearg(args, &x)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
174 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
175 errno = 0; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
176 x = frexp(x, &i); |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
177 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
178 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
179 return math_error(); |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
180 return mkvalue("(di)", x, i); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
181 } |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
182 |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
183 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
184 math_ldexp(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
185 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
186 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
187 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
188 double x, y; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
189 /* Cheat -- allow float as second argument */ |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
190 if (!get2doublearg(args, &x, &y)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
191 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
192 errno = 0; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
193 x = ldexp(x, (int)y); |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
194 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
195 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
196 return math_error(); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
197 else |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
198 return newfloatobject(x); |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
199 } |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
200 |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
201 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
202 math_modf(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
203 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
204 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
205 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
206 double x, y; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
207 if (!getdoublearg(args, &x)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
208 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
209 errno = 0; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
210 #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:
1319
diff
changeset
|
211 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
212 extended e; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
213 x = modf(x, &e); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
214 y = e; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
215 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
216 #else |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
217 x = modf(x, &y); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
218 #endif |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
219 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
220 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
221 return math_error(); |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
222 return mkvalue("(dd)", x, y); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
223 } |
| 6 | 224 |
| 225 static struct methodlist math_methods[] = { | |
| 226 {"acos", math_acos}, | |
| 227 {"asin", math_asin}, | |
| 228 {"atan", math_atan}, | |
| 229 {"atan2", math_atan2}, | |
| 230 {"ceil", math_ceil}, | |
| 231 {"cos", math_cos}, | |
| 232 {"cosh", math_cosh}, | |
| 233 {"exp", math_exp}, | |
| 234 {"fabs", math_fabs}, | |
| 235 {"floor", math_floor}, | |
| 236 {"fmod", math_fmod}, | |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
237 {"frexp", math_frexp}, |
| 1986 | 238 {"hypot", math_hypot}, |
| 6 | 239 {"ldexp", math_ldexp}, |
| 240 {"log", math_log}, | |
| 241 {"log10", math_log10}, | |
| 242 {"modf", math_modf}, | |
| 243 {"pow", math_pow}, | |
| 244 {"sin", math_sin}, | |
| 245 {"sinh", math_sinh}, | |
| 246 {"sqrt", math_sqrt}, | |
| 247 {"tan", math_tan}, | |
| 248 {"tanh", math_tanh}, | |
| 249 {NULL, NULL} /* sentinel */ | |
| 250 }; | |
| 251 | |
| 252 void | |
| 253 initmath() | |
| 254 { | |
| 255 object *m, *d, *v; | |
|
42
4835c2d38b84
Take out duplication of code in initmodule().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
256 |
|
4835c2d38b84
Take out duplication of code in initmodule().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
257 m = initmodule("math", math_methods); |
| 6 | 258 d = getmoduledict(m); |
|
75
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
259 dictinsert(d, "pi", v = newfloatobject(atan(1.0) * 4.0)); |
|
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
260 DECREF(v); |
|
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
261 dictinsert(d, "e", v = newfloatobject(exp(1.0))); |
|
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
262 DECREF(v); |
| 6 | 263 } |
