Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | /* Math module -- standard C math library functions, pi and e */ |
| 33 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 35 | |
Guido van Rossum | 6964f73 | 1995-03-01 10:34:29 +0000 | [diff] [blame] | 36 | #include "mymath.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | 7081cf5 | 1996-05-23 22:56:19 +0000 | [diff] [blame] | 38 | #ifndef _MSC_VER |
Guido van Rossum | b941868 | 1995-01-12 11:28:16 +0000 | [diff] [blame] | 39 | #ifndef __STDC__ |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 40 | extern double fmod Py_PROTO((double, double)); |
| 41 | extern double frexp Py_PROTO((double, int *)); |
| 42 | extern double ldexp Py_PROTO((double, int)); |
| 43 | extern double modf Py_PROTO((double, double *)); |
Guido van Rossum | 7081cf5 | 1996-05-23 22:56:19 +0000 | [diff] [blame] | 44 | #endif /* __STDC__ */ |
| 45 | #endif /* _MSC_VER */ |
| 46 | |
Guido van Rossum | b941868 | 1995-01-12 11:28:16 +0000 | [diff] [blame] | 47 | |
Guido van Rossum | 9575a44 | 1993-04-07 14:06:14 +0000 | [diff] [blame] | 48 | #ifdef i860 |
| 49 | /* Cray APP has bogus definition of HUGE_VAL in <math.h> */ |
| 50 | #undef HUGE_VAL |
| 51 | #endif |
| 52 | |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 53 | #ifdef HUGE_VAL |
| 54 | #define CHECK(x) if (errno != 0) ; \ |
| 55 | else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \ |
| 56 | else errno = ERANGE |
| 57 | #else |
| 58 | #define CHECK(x) /* Don't know how to check */ |
| 59 | #endif |
| 60 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 61 | static PyObject * |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 62 | math_error() |
| 63 | { |
| 64 | if (errno == EDOM) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 65 | PyErr_SetString(PyExc_ValueError, "math domain error"); |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 66 | else if (errno == ERANGE) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 67 | PyErr_SetString(PyExc_OverflowError, "math range error"); |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 68 | else |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 69 | /* Unexpected math error */ |
| 70 | PyErr_SetFromErrno(PyExc_ValueError); |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 71 | return NULL; |
| 72 | } |
| 73 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 74 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 75 | math_1(args, func) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 76 | PyObject *args; |
| 77 | double (*func) Py_FPROTO((double)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 78 | { |
| 79 | double x; |
Roger E. Masse | 20c6381 | 1996-12-18 21:59:01 +0000 | [diff] [blame] | 80 | if (! PyArg_Parse(args, "d", &x)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 81 | return NULL; |
| 82 | errno = 0; |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 83 | PyFPE_START_PROTECT("in math_1", return 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 84 | x = (*func)(x); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 85 | PyFPE_END_PROTECT(x) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 86 | CHECK(x); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 87 | if (errno != 0) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 88 | return math_error(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 89 | else |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 90 | return PyFloat_FromDouble(x); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 93 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 94 | math_2(args, func) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 95 | PyObject *args; |
| 96 | double (*func) Py_FPROTO((double, double)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 97 | { |
| 98 | double x, y; |
Roger E. Masse | 20c6381 | 1996-12-18 21:59:01 +0000 | [diff] [blame] | 99 | if (! PyArg_Parse(args, "(dd)", &x, &y)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 100 | return NULL; |
| 101 | errno = 0; |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 102 | PyFPE_START_PROTECT("in math_2", return 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 103 | x = (*func)(x, y); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 104 | PyFPE_END_PROTECT(x) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 105 | CHECK(x); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 106 | if (errno != 0) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 107 | return math_error(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 108 | else |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 109 | return PyFloat_FromDouble(x); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | #define FUNC1(stubname, func) \ |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 113 | static PyObject * stubname(self, args) PyObject *self, *args; { \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 114 | return math_1(args, func); \ |
| 115 | } |
| 116 | |
| 117 | #define FUNC2(stubname, func) \ |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 118 | static PyObject * stubname(self, args) PyObject *self, *args; { \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 119 | return math_2(args, func); \ |
| 120 | } |
| 121 | |
| 122 | FUNC1(math_acos, acos) |
| 123 | FUNC1(math_asin, asin) |
| 124 | FUNC1(math_atan, atan) |
| 125 | FUNC2(math_atan2, atan2) |
| 126 | FUNC1(math_ceil, ceil) |
| 127 | FUNC1(math_cos, cos) |
| 128 | FUNC1(math_cosh, cosh) |
| 129 | FUNC1(math_exp, exp) |
| 130 | FUNC1(math_fabs, fabs) |
| 131 | FUNC1(math_floor, floor) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 132 | FUNC2(math_fmod, fmod) |
Guido van Rossum | 411a8bd | 1994-10-20 22:00:28 +0000 | [diff] [blame] | 133 | FUNC2(math_hypot, hypot) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 134 | FUNC1(math_log, log) |
| 135 | FUNC1(math_log10, log10) |
Guido van Rossum | 1492c27 | 1991-07-27 21:38:43 +0000 | [diff] [blame] | 136 | #ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */ |
Guido van Rossum | 76f2f2e | 1991-06-24 22:23:10 +0000 | [diff] [blame] | 137 | FUNC2(math_pow, power) |
| 138 | #else |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 139 | FUNC2(math_pow, pow) |
Guido van Rossum | 76f2f2e | 1991-06-24 22:23:10 +0000 | [diff] [blame] | 140 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 141 | FUNC1(math_sin, sin) |
| 142 | FUNC1(math_sinh, sinh) |
| 143 | FUNC1(math_sqrt, sqrt) |
| 144 | FUNC1(math_tan, tan) |
| 145 | FUNC1(math_tanh, tanh) |
| 146 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 147 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 148 | static PyObject * |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 149 | math_frexp(self, args) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 150 | PyObject *self; |
| 151 | PyObject *args; |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 152 | { |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 153 | double x; |
| 154 | int i; |
Roger E. Masse | 20c6381 | 1996-12-18 21:59:01 +0000 | [diff] [blame] | 155 | if (! PyArg_Parse(args, "d", &x)) |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 156 | return NULL; |
| 157 | errno = 0; |
| 158 | x = frexp(x, &i); |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 159 | CHECK(x); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 160 | if (errno != 0) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 161 | return math_error(); |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 162 | return Py_BuildValue("(di)", x, i); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 165 | static PyObject * |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 166 | math_ldexp(self, args) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 167 | PyObject *self; |
| 168 | PyObject *args; |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 169 | { |
| 170 | double x, y; |
| 171 | /* Cheat -- allow float as second argument */ |
Roger E. Masse | 20c6381 | 1996-12-18 21:59:01 +0000 | [diff] [blame] | 172 | if (! PyArg_Parse(args, "(dd)", &x, &y)) |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 173 | return NULL; |
| 174 | errno = 0; |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 175 | PyFPE_START_PROTECT("ldexp", return 0) |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 176 | x = ldexp(x, (int)y); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 177 | PyFPE_END_PROTECT(x) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 178 | CHECK(x); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 179 | if (errno != 0) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 180 | return math_error(); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 181 | else |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 182 | return PyFloat_FromDouble(x); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 185 | static PyObject * |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 186 | math_modf(self, args) |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 187 | PyObject *self; |
| 188 | PyObject *args; |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 189 | { |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 190 | double x, y; |
Roger E. Masse | 20c6381 | 1996-12-18 21:59:01 +0000 | [diff] [blame] | 191 | if (! PyArg_Parse(args, "d", &x)) |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 192 | return NULL; |
| 193 | errno = 0; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 194 | #ifdef MPW /* MPW C modf expects pointer to extended as second argument */ |
| 195 | { |
| 196 | extended e; |
| 197 | x = modf(x, &e); |
| 198 | y = e; |
| 199 | } |
| 200 | #else |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 201 | x = modf(x, &y); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 202 | #endif |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 203 | CHECK(x); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 204 | if (errno != 0) |
Guido van Rossum | 8832b62 | 1991-12-16 15:44:24 +0000 | [diff] [blame] | 205 | return math_error(); |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 206 | return Py_BuildValue("(dd)", x, y); |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 207 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 208 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 209 | static PyMethodDef math_methods[] = { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 210 | {"acos", math_acos}, |
| 211 | {"asin", math_asin}, |
| 212 | {"atan", math_atan}, |
| 213 | {"atan2", math_atan2}, |
| 214 | {"ceil", math_ceil}, |
| 215 | {"cos", math_cos}, |
| 216 | {"cosh", math_cosh}, |
| 217 | {"exp", math_exp}, |
| 218 | {"fabs", math_fabs}, |
| 219 | {"floor", math_floor}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 220 | {"fmod", math_fmod}, |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 221 | {"frexp", math_frexp}, |
Guido van Rossum | 411a8bd | 1994-10-20 22:00:28 +0000 | [diff] [blame] | 222 | {"hypot", math_hypot}, |
Guido van Rossum | d18ad58 | 1991-10-24 14:57:21 +0000 | [diff] [blame] | 223 | {"ldexp", math_ldexp}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 224 | {"log", math_log}, |
| 225 | {"log10", math_log10}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 226 | {"modf", math_modf}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 227 | {"pow", math_pow}, |
| 228 | {"sin", math_sin}, |
| 229 | {"sinh", math_sinh}, |
| 230 | {"sqrt", math_sqrt}, |
| 231 | {"tan", math_tan}, |
| 232 | {"tanh", math_tanh}, |
| 233 | {NULL, NULL} /* sentinel */ |
| 234 | }; |
| 235 | |
| 236 | void |
| 237 | initmath() |
| 238 | { |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 239 | PyObject *m, *d, *v; |
Guido van Rossum | 738d4dd | 1990-10-26 14:59:30 +0000 | [diff] [blame] | 240 | |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 241 | m = Py_InitModule("math", math_methods); |
| 242 | d = PyModule_GetDict(m); |
Barry Warsaw | fc93f75 | 1996-12-17 00:47:03 +0000 | [diff] [blame] | 243 | |
| 244 | if (!(v = PyFloat_FromDouble(atan(1.0) * 4.0))) |
| 245 | goto finally; |
| 246 | if (PyDict_SetItemString(d, "pi", v) < 0) |
| 247 | goto finally; |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 248 | Py_DECREF(v); |
Barry Warsaw | fc93f75 | 1996-12-17 00:47:03 +0000 | [diff] [blame] | 249 | |
| 250 | if (!(v = PyFloat_FromDouble(exp(1.0)))) |
| 251 | goto finally; |
Guido van Rossum | 4c4cbf3 | 1996-12-18 14:12:22 +0000 | [diff] [blame] | 252 | if (PyDict_SetItemString(d, "e", v) < 0) |
Barry Warsaw | fc93f75 | 1996-12-17 00:47:03 +0000 | [diff] [blame] | 253 | goto finally; |
Barry Warsaw | 8b43b19 | 1996-12-09 22:32:36 +0000 | [diff] [blame] | 254 | Py_DECREF(v); |
Guido van Rossum | 4a48809 | 1996-12-18 14:14:33 +0000 | [diff] [blame] | 255 | return; |
Barry Warsaw | fc93f75 | 1996-12-17 00:47:03 +0000 | [diff] [blame] | 256 | |
| 257 | finally: |
| 258 | Py_FatalError("can't initialize math module"); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 259 | } |