Commit 24070ca3 authored by Roger E. Masse's avatar Roger E. Masse

Renamed Grandly

parent 3daddda1
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
/* much code borrowed from mathmodule.c */ /* much code borrowed from mathmodule.c */
#include "allobjects.h" #include "Python.h"
#include "complexobject.h"
#include <errno.h> #include <errno.h>
...@@ -229,22 +228,22 @@ static Py_complex c_tanh(x) ...@@ -229,22 +228,22 @@ static Py_complex c_tanh(x)
/* And now the glue to make them available from Python: */ /* And now the glue to make them available from Python: */
static object * static PyObject *
math_error() math_error()
{ {
if (errno == EDOM) if (errno == EDOM)
err_setstr(ValueError, "math domain error"); PyErr_SetString(PyExc_ValueError, "math domain error");
else if (errno == ERANGE) else if (errno == ERANGE)
err_setstr(OverflowError, "math range error"); PyErr_SetString(PyExc_OverflowError, "math range error");
else else /* Unexpected math error */
err_errno(ValueError); /* Unexpected math error */ PyErr_SetFromErrno(PyExc_ValueError);
return NULL; return NULL;
} }
static object * static PyObject *
math_1(args, func) math_1(args, func)
object *args; PyObject *args;
Py_complex (*func) FPROTO((Py_complex)); Py_complex (*func) Py_FPROTO((Py_complex));
{ {
Py_complex x; Py_complex x;
if (!PyArg_ParseTuple(args, "D", &x)) if (!PyArg_ParseTuple(args, "D", &x))
...@@ -256,11 +255,11 @@ math_1(args, func) ...@@ -256,11 +255,11 @@ math_1(args, func)
if (errno != 0) if (errno != 0)
return math_error(); return math_error();
else else
return newcomplexobject(x); return PyComplex_FromCComplex(x);
} }
#define FUNC1(stubname, func) \ #define FUNC1(stubname, func) \
static object * stubname(self, args) object *self, *args; { \ static PyObject * stubname(self, args) PyObject *self, *args; { \
return math_1(args, func); \ return math_1(args, func); \
} }
...@@ -282,7 +281,7 @@ FUNC1(cmath_tan, c_tan) ...@@ -282,7 +281,7 @@ FUNC1(cmath_tan, c_tan)
FUNC1(cmath_tanh, c_tanh) FUNC1(cmath_tanh, c_tanh)
static struct methodlist cmath_methods[] = { static PyMethodDef cmath_methods[] = {
{"acos", cmath_acos, 1}, {"acos", cmath_acos, 1},
{"acosh", cmath_acosh, 1}, {"acosh", cmath_acosh, 1},
{"asin", cmath_asin, 1}, {"asin", cmath_asin, 1},
...@@ -305,12 +304,13 @@ static struct methodlist cmath_methods[] = { ...@@ -305,12 +304,13 @@ static struct methodlist cmath_methods[] = {
void void
initcmath() initcmath()
{ {
object *m, *d, *v; PyObject *m, *d, *v;
m = Py_InitModule("cmath", cmath_methods); m = Py_InitModule("cmath", cmath_methods);
d = getmoduledict(m); d = PyModule_GetDict(m);
dictinsert(d, "pi", v = newfloatobject(atan(1.0) * 4.0)); PyDict_SetItemString(d, "pi",
DECREF(v); v = PyFloat_FromDouble(atan(1.0) * 4.0));
dictinsert(d, "e", v = newfloatobject(exp(1.0))); Py_DECREF(v);
DECREF(v); PyDict_SetItemString(d, "e", v = PyFloat_FromDouble(exp(1.0)));
Py_DECREF(v);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment