Mercurial > cpython-lru_cache-weakref
annotate Modules/mathmodule.c @ 4439:fb1237bf7022 legacy-trunk
Changed version to plain "1.4".
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 22 Oct 1996 03:09:46 +0000 |
| parents | 28174aa38c76 |
| children | 65d2d8e67da3 |
| 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 |
|
1271
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
46 #ifdef i860 |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
47 /* 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
|
48 #undef HUGE_VAL |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
49 #endif |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
50 |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
51 #ifdef HUGE_VAL |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
52 #define CHECK(x) if (errno != 0) ; \ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
53 else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
54 else errno = ERANGE |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
55 #else |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
56 #define CHECK(x) /* Don't know how to check */ |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
57 #endif |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
58 |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
59 static object * |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
60 math_error() |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
61 { |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
62 if (errno == EDOM) |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
63 err_setstr(ValueError, "math domain error"); |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
64 else if (errno == ERANGE) |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
65 err_setstr(OverflowError, "math range error"); |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
66 else |
|
679
6a60342c3107
Get rid of RuntimeError.
Guido van Rossum <guido@python.org>
parents:
591
diff
changeset
|
67 err_errno(ValueError); /* Unexpected math error */ |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
68 return NULL; |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
69 } |
|
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
70 |
| 6 | 71 static object * |
| 72 math_1(args, func) | |
| 73 object *args; | |
| 74 double (*func) FPROTO((double)); | |
| 75 { | |
| 76 double x; | |
| 77 if (!getdoublearg(args, &x)) | |
| 78 return NULL; | |
| 79 errno = 0; | |
| 80 x = (*func)(x); | |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
81 CHECK(x); |
| 6 | 82 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
83 return math_error(); |
| 6 | 84 else |
| 85 return newfloatobject(x); | |
| 86 } | |
| 87 | |
| 88 static object * | |
| 89 math_2(args, func) | |
| 90 object *args; | |
| 91 double (*func) FPROTO((double, double)); | |
| 92 { | |
| 93 double x, y; | |
| 94 if (!get2doublearg(args, &x, &y)) | |
| 95 return NULL; | |
| 96 errno = 0; | |
| 97 x = (*func)(x, y); | |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
98 CHECK(x); |
| 6 | 99 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
100 return math_error(); |
| 6 | 101 else |
| 102 return newfloatobject(x); | |
| 103 } | |
| 104 | |
| 105 #define FUNC1(stubname, func) \ | |
| 106 static object * stubname(self, args) object *self, *args; { \ | |
| 107 return math_1(args, func); \ | |
| 108 } | |
| 109 | |
| 110 #define FUNC2(stubname, func) \ | |
| 111 static object * stubname(self, args) object *self, *args; { \ | |
| 112 return math_2(args, func); \ | |
| 113 } | |
| 114 | |
| 115 FUNC1(math_acos, acos) | |
| 116 FUNC1(math_asin, asin) | |
| 117 FUNC1(math_atan, atan) | |
| 118 FUNC2(math_atan2, atan2) | |
| 119 FUNC1(math_ceil, ceil) | |
| 120 FUNC1(math_cos, cos) | |
| 121 FUNC1(math_cosh, cosh) | |
| 122 FUNC1(math_exp, exp) | |
|
3974
fc505f02ad8a
Hack for Mac (where fabs is not usable as a function pointer).
Guido van Rossum <guido@python.org>
parents:
3881
diff
changeset
|
123 #ifdef __MWERKS__ |
|
fc505f02ad8a
Hack for Mac (where fabs is not usable as a function pointer).
Guido van Rossum <guido@python.org>
parents:
3881
diff
changeset
|
124 double myfabs(double x) { return fabs(x); } |
|
fc505f02ad8a
Hack for Mac (where fabs is not usable as a function pointer).
Guido van Rossum <guido@python.org>
parents:
3881
diff
changeset
|
125 FUNC1(math_fabs, myfabs) |
|
fc505f02ad8a
Hack for Mac (where fabs is not usable as a function pointer).
Guido van Rossum <guido@python.org>
parents:
3881
diff
changeset
|
126 #else |
| 6 | 127 FUNC1(math_fabs, fabs) |
|
3974
fc505f02ad8a
Hack for Mac (where fabs is not usable as a function pointer).
Guido van Rossum <guido@python.org>
parents:
3881
diff
changeset
|
128 #endif |
| 6 | 129 FUNC1(math_floor, floor) |
| 130 FUNC2(math_fmod, fmod) | |
| 1986 | 131 FUNC2(math_hypot, hypot) |
| 6 | 132 FUNC1(math_log, log) |
| 133 FUNC1(math_log10, log10) | |
|
320
26426c42a162
Add some err_errno calls that were missing
Guido van Rossum <guido@python.org>
parents:
289
diff
changeset
|
134 #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
|
135 FUNC2(math_pow, power) |
|
c4c278c56e90
Apparently MPW has power() instead of pow().
Guido van Rossum <guido@python.org>
parents:
168
diff
changeset
|
136 #else |
| 6 | 137 FUNC2(math_pow, pow) |
|
289
c4c278c56e90
Apparently MPW has power() instead of pow().
Guido van Rossum <guido@python.org>
parents:
168
diff
changeset
|
138 #endif |
| 6 | 139 FUNC1(math_sin, sin) |
| 140 FUNC1(math_sinh, sinh) | |
| 141 FUNC1(math_sqrt, sqrt) | |
| 142 FUNC1(math_tan, tan) | |
| 143 FUNC1(math_tanh, tanh) | |
| 144 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
145 |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
146 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
147 math_frexp(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
148 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
149 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
150 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
151 double x; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
152 int i; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
153 if (!getdoublearg(args, &x)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
154 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
155 errno = 0; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
156 x = frexp(x, &i); |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
157 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
158 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
159 return math_error(); |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
160 return mkvalue("(di)", x, i); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
161 } |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
162 |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
163 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
164 math_ldexp(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
165 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
166 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
167 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
168 double x, y; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
169 /* Cheat -- allow float as second argument */ |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
170 if (!get2doublearg(args, &x, &y)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
171 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
172 errno = 0; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
173 x = ldexp(x, (int)y); |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
174 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
175 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
176 return math_error(); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
177 else |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
178 return newfloatobject(x); |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
179 } |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
180 |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
181 static object * |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
182 math_modf(self, args) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
183 object *self; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
184 object *args; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
185 { |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
186 double x, y; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
187 if (!getdoublearg(args, &x)) |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
188 return NULL; |
|
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
189 errno = 0; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
190 #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
|
191 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
192 extended e; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
193 x = modf(x, &e); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
194 y = e; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
195 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
196 #else |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
197 x = modf(x, &y); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
198 #endif |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
199 CHECK(x); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
200 if (errno != 0) |
|
498
56bb1067a880
Improve error handling.
Guido van Rossum <guido@python.org>
parents:
438
diff
changeset
|
201 return math_error(); |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
202 return mkvalue("(dd)", x, y); |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
203 } |
| 6 | 204 |
| 205 static struct methodlist math_methods[] = { | |
| 206 {"acos", math_acos}, | |
| 207 {"asin", math_asin}, | |
| 208 {"atan", math_atan}, | |
| 209 {"atan2", math_atan2}, | |
| 210 {"ceil", math_ceil}, | |
| 211 {"cos", math_cos}, | |
| 212 {"cosh", math_cosh}, | |
| 213 {"exp", math_exp}, | |
| 214 {"fabs", math_fabs}, | |
| 215 {"floor", math_floor}, | |
| 216 {"fmod", math_fmod}, | |
|
407
9b3d557665a9
Added frexp, ldexp, modf, fmod.
Guido van Rossum <guido@python.org>
parents:
320
diff
changeset
|
217 {"frexp", math_frexp}, |
| 1986 | 218 {"hypot", math_hypot}, |
| 6 | 219 {"ldexp", math_ldexp}, |
| 220 {"log", math_log}, | |
| 221 {"log10", math_log10}, | |
| 222 {"modf", math_modf}, | |
| 223 {"pow", math_pow}, | |
| 224 {"sin", math_sin}, | |
| 225 {"sinh", math_sinh}, | |
| 226 {"sqrt", math_sqrt}, | |
| 227 {"tan", math_tan}, | |
| 228 {"tanh", math_tanh}, | |
| 229 {NULL, NULL} /* sentinel */ | |
| 230 }; | |
| 231 | |
| 232 void | |
| 233 initmath() | |
| 234 { | |
| 235 object *m, *d, *v; | |
|
42
4835c2d38b84
Take out duplication of code in initmodule().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
236 |
|
4835c2d38b84
Take out duplication of code in initmodule().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
237 m = initmodule("math", math_methods); |
| 6 | 238 d = getmoduledict(m); |
|
75
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
239 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
|
240 DECREF(v); |
|
85eed060a46c
DECREF pi and e after inserting in symbol table.
Guido van Rossum <guido@python.org>
parents:
42
diff
changeset
|
241 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
|
242 DECREF(v); |
| 6 | 243 } |
