1996-01-12 01:34:57 +00:00
|
|
|
/* Complex math module */
|
|
|
|
|
|
|
|
/* much code borrowed from mathmodule.c */
|
|
|
|
|
1996-12-09 22:59:53 +00:00
|
|
|
#include "Python.h"
|
1996-01-12 01:34:57 +00:00
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI (3.141592653589793239)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* First, the C functions that do the real work */
|
|
|
|
|
|
|
|
/* constants */
|
2001-02-20 20:36:38 +00:00
|
|
|
static Py_complex c_one = {1., 0.};
|
1996-07-21 02:31:35 +00:00
|
|
|
static Py_complex c_half = {0.5, 0.};
|
|
|
|
static Py_complex c_i = {0., 1.};
|
2001-02-20 20:36:38 +00:00
|
|
|
static Py_complex c_halfi = {0., 0.5};
|
1996-01-12 01:34:57 +00:00
|
|
|
|
|
|
|
/* forward declarations */
|
2002-07-17 16:30:39 +00:00
|
|
|
static Py_complex c_log(Py_complex);
|
|
|
|
static Py_complex c_prodi(Py_complex);
|
|
|
|
static Py_complex c_sqrt(Py_complex);
|
1996-01-12 01:34:57 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_acos(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
|
|
|
return c_neg(c_prodi(c_log(c_sum(x,c_prod(c_i,
|
2001-02-20 20:36:38 +00:00
|
|
|
c_sqrt(c_diff(c_one,c_prod(x,x))))))));
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_acos_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"acos(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the arc cosine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_acosh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
2000-06-30 02:29:22 +00:00
|
|
|
Py_complex z;
|
|
|
|
z = c_sqrt(c_half);
|
2001-02-20 20:36:38 +00:00
|
|
|
z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x,c_one)),
|
|
|
|
c_sqrt(c_diff(x,c_one)))));
|
2000-06-30 02:29:22 +00:00
|
|
|
return c_sum(z, z);
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_acosh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"acosh(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic arccosine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_asin(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
2001-02-21 03:22:39 +00:00
|
|
|
/* -i * log[(sqrt(1-x**2) + i*x] */
|
|
|
|
const Py_complex squared = c_prod(x, x);
|
|
|
|
const Py_complex sqrt_1_minus_x_sq = c_sqrt(c_diff(c_one, squared));
|
2001-02-22 19:51:56 +00:00
|
|
|
return c_neg(c_prodi(c_log(
|
|
|
|
c_sum(sqrt_1_minus_x_sq, c_prodi(x))
|
|
|
|
) ) );
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_asin_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"asin(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the arc sine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_asinh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1999-01-14 19:11:11 +00:00
|
|
|
Py_complex z;
|
2001-02-21 03:22:39 +00:00
|
|
|
z = c_sqrt(c_half);
|
|
|
|
z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)),
|
|
|
|
c_sqrt(c_diff(x, c_i)))));
|
|
|
|
return c_sum(z, z);
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_asinh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"asinh(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic arc sine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_atan(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
2001-02-20 20:36:38 +00:00
|
|
|
return c_prod(c_halfi,c_log(c_quot(c_sum(c_i,x),c_diff(c_i,x))));
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_atan_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"atan(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the arc tangent of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_atanh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
2001-02-20 20:36:38 +00:00
|
|
|
return c_prod(c_half,c_log(c_quot(c_sum(c_one,x),c_diff(c_one,x))));
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_atanh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"atanh(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic arc tangent of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_cos(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
r.real = cos(x.real)*cosh(x.imag);
|
|
|
|
r.imag = -sin(x.real)*sinh(x.imag);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_cos_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"cos(x)\n"
|
|
|
|
"n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the cosine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_cosh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
r.real = cos(x.imag)*cosh(x.real);
|
|
|
|
r.imag = sin(x.imag)*sinh(x.real);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_cosh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"cosh(x)\n"
|
|
|
|
"n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic cosine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_exp(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double l = exp(x.real);
|
|
|
|
r.real = l*cos(x.imag);
|
|
|
|
r.imag = l*sin(x.imag);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_exp_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"exp(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the exponential value e**x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_log(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double l = hypot(x.real,x.imag);
|
2001-09-06 08:16:17 +00:00
|
|
|
r.imag = atan2(x.imag, x.real);
|
1996-01-12 01:34:57 +00:00
|
|
|
r.real = log(l);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_log_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"log(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the natural logarithm of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_log10(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double l = hypot(x.real,x.imag);
|
2001-09-06 08:16:17 +00:00
|
|
|
r.imag = atan2(x.imag, x.real)/log(10.);
|
1996-01-12 01:34:57 +00:00
|
|
|
r.real = log10(l);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_log10_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"log10(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the base-10 logarithm of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* internal function not available from Python */
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_prodi(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
r.real = -x.imag;
|
|
|
|
r.imag = x.real;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
1998-12-04 19:26:43 +00:00
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_sin(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
2001-02-20 20:15:19 +00:00
|
|
|
r.real = sin(x.real) * cosh(x.imag);
|
|
|
|
r.imag = cos(x.real) * sinh(x.imag);
|
1996-01-12 01:34:57 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_sin_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"sin(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the sine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_sinh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
2001-02-20 20:15:19 +00:00
|
|
|
r.real = cos(x.imag) * sinh(x.real);
|
|
|
|
r.imag = sin(x.imag) * cosh(x.real);
|
1996-01-12 01:34:57 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_sinh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"sinh(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic sine of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_sqrt(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double s,d;
|
|
|
|
if (x.real == 0. && x.imag == 0.)
|
|
|
|
r = x;
|
|
|
|
else {
|
|
|
|
s = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag)));
|
|
|
|
d = 0.5*x.imag/s;
|
|
|
|
if (x.real > 0.) {
|
|
|
|
r.real = s;
|
|
|
|
r.imag = d;
|
|
|
|
}
|
|
|
|
else if (x.imag >= 0.) {
|
|
|
|
r.real = d;
|
|
|
|
r.imag = s;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r.real = -d;
|
|
|
|
r.imag = -s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_sqrt_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"sqrt(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the square root of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_tan(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double sr,cr,shi,chi;
|
|
|
|
double rs,is,rc,ic;
|
|
|
|
double d;
|
|
|
|
sr = sin(x.real);
|
|
|
|
cr = cos(x.real);
|
|
|
|
shi = sinh(x.imag);
|
|
|
|
chi = cosh(x.imag);
|
2001-02-20 20:15:19 +00:00
|
|
|
rs = sr * chi;
|
|
|
|
is = cr * shi;
|
|
|
|
rc = cr * chi;
|
|
|
|
ic = -sr * shi;
|
|
|
|
d = rc*rc + ic * ic;
|
|
|
|
r.real = (rs*rc + is*ic) / d;
|
|
|
|
r.imag = (is*rc - rs*ic) / d;
|
1996-01-12 01:34:57 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_tan_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"tan(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the tangent of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
|
|
|
|
2001-02-20 20:15:19 +00:00
|
|
|
static Py_complex
|
|
|
|
c_tanh(Py_complex x)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex r;
|
1996-01-12 01:34:57 +00:00
|
|
|
double si,ci,shr,chr;
|
|
|
|
double rs,is,rc,ic;
|
|
|
|
double d;
|
|
|
|
si = sin(x.imag);
|
|
|
|
ci = cos(x.imag);
|
|
|
|
shr = sinh(x.real);
|
|
|
|
chr = cosh(x.real);
|
2001-02-20 20:15:19 +00:00
|
|
|
rs = ci * shr;
|
|
|
|
is = si * chr;
|
|
|
|
rc = ci * chr;
|
|
|
|
ic = si * shr;
|
1996-01-12 01:34:57 +00:00
|
|
|
d = rc*rc + ic*ic;
|
2001-02-20 20:15:19 +00:00
|
|
|
r.real = (rs*rc + is*ic) / d;
|
|
|
|
r.imag = (is*rc - rs*ic) / d;
|
1996-01-12 01:34:57 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(c_tanh_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"tanh(x)\n"
|
|
|
|
"\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"Return the hyperbolic tangent of x.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
1996-01-12 01:34:57 +00:00
|
|
|
|
|
|
|
/* And now the glue to make them available from Python: */
|
|
|
|
|
1996-12-09 22:59:53 +00:00
|
|
|
static PyObject *
|
2000-07-21 06:00:07 +00:00
|
|
|
math_error(void)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
|
|
|
if (errno == EDOM)
|
1996-12-09 22:59:53 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "math domain error");
|
1996-01-12 01:34:57 +00:00
|
|
|
else if (errno == ERANGE)
|
1996-12-09 22:59:53 +00:00
|
|
|
PyErr_SetString(PyExc_OverflowError, "math range error");
|
|
|
|
else /* Unexpected math error */
|
2001-02-20 20:15:19 +00:00
|
|
|
PyErr_SetFromErrno(PyExc_ValueError);
|
1996-01-12 01:34:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1996-12-09 22:59:53 +00:00
|
|
|
static PyObject *
|
2000-07-10 09:31:34 +00:00
|
|
|
math_1(PyObject *args, Py_complex (*func)(Py_complex))
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
1996-07-21 02:31:35 +00:00
|
|
|
Py_complex x;
|
1996-01-12 01:34:57 +00:00
|
|
|
if (!PyArg_ParseTuple(args, "D", &x))
|
|
|
|
return NULL;
|
|
|
|
errno = 0;
|
1997-02-14 22:59:58 +00:00
|
|
|
PyFPE_START_PROTECT("complex function", return 0)
|
1996-01-12 01:34:57 +00:00
|
|
|
x = (*func)(x);
|
1997-03-14 04:32:50 +00:00
|
|
|
PyFPE_END_PROTECT(x)
|
2002-03-09 04:58:24 +00:00
|
|
|
Py_ADJUST_ERANGE2(x.real, x.imag);
|
1996-01-12 01:34:57 +00:00
|
|
|
if (errno != 0)
|
|
|
|
return math_error();
|
|
|
|
else
|
1996-12-09 22:59:53 +00:00
|
|
|
return PyComplex_FromCComplex(x);
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FUNC1(stubname, func) \
|
2000-07-10 09:31:34 +00:00
|
|
|
static PyObject * stubname(PyObject *self, PyObject *args) { \
|
1996-01-12 01:34:57 +00:00
|
|
|
return math_1(args, func); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FUNC1(cmath_acos, c_acos)
|
|
|
|
FUNC1(cmath_acosh, c_acosh)
|
|
|
|
FUNC1(cmath_asin, c_asin)
|
|
|
|
FUNC1(cmath_asinh, c_asinh)
|
|
|
|
FUNC1(cmath_atan, c_atan)
|
|
|
|
FUNC1(cmath_atanh, c_atanh)
|
|
|
|
FUNC1(cmath_cos, c_cos)
|
|
|
|
FUNC1(cmath_cosh, c_cosh)
|
|
|
|
FUNC1(cmath_exp, c_exp)
|
|
|
|
FUNC1(cmath_log, c_log)
|
|
|
|
FUNC1(cmath_log10, c_log10)
|
|
|
|
FUNC1(cmath_sin, c_sin)
|
|
|
|
FUNC1(cmath_sinh, c_sinh)
|
|
|
|
FUNC1(cmath_sqrt, c_sqrt)
|
|
|
|
FUNC1(cmath_tan, c_tan)
|
|
|
|
FUNC1(cmath_tanh, c_tanh)
|
|
|
|
|
|
|
|
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(module_doc,
|
2001-02-20 20:15:19 +00:00
|
|
|
"This module is always available. It provides access to mathematical\n"
|
2002-06-13 20:33:02 +00:00
|
|
|
"functions for complex numbers.");
|
1998-12-04 19:26:43 +00:00
|
|
|
|
1996-12-09 22:59:53 +00:00
|
|
|
static PyMethodDef cmath_methods[] = {
|
2001-02-20 20:15:19 +00:00
|
|
|
{"acos", cmath_acos, METH_VARARGS, c_acos_doc},
|
|
|
|
{"acosh", cmath_acosh, METH_VARARGS, c_acosh_doc},
|
|
|
|
{"asin", cmath_asin, METH_VARARGS, c_asin_doc},
|
|
|
|
{"asinh", cmath_asinh, METH_VARARGS, c_asinh_doc},
|
|
|
|
{"atan", cmath_atan, METH_VARARGS, c_atan_doc},
|
|
|
|
{"atanh", cmath_atanh, METH_VARARGS, c_atanh_doc},
|
|
|
|
{"cos", cmath_cos, METH_VARARGS, c_cos_doc},
|
|
|
|
{"cosh", cmath_cosh, METH_VARARGS, c_cosh_doc},
|
|
|
|
{"exp", cmath_exp, METH_VARARGS, c_exp_doc},
|
|
|
|
{"log", cmath_log, METH_VARARGS, c_log_doc},
|
|
|
|
{"log10", cmath_log10, METH_VARARGS, c_log10_doc},
|
|
|
|
{"sin", cmath_sin, METH_VARARGS, c_sin_doc},
|
|
|
|
{"sinh", cmath_sinh, METH_VARARGS, c_sinh_doc},
|
|
|
|
{"sqrt", cmath_sqrt, METH_VARARGS, c_sqrt_doc},
|
|
|
|
{"tan", cmath_tan, METH_VARARGS, c_tan_doc},
|
|
|
|
{"tanh", cmath_tanh, METH_VARARGS, c_tanh_doc},
|
1996-01-12 01:34:57 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
2002-08-02 02:27:13 +00:00
|
|
|
PyMODINIT_FUNC
|
2000-07-21 06:00:07 +00:00
|
|
|
initcmath(void)
|
1996-01-12 01:34:57 +00:00
|
|
|
{
|
2002-04-01 03:45:06 +00:00
|
|
|
PyObject *m;
|
2001-02-20 20:15:19 +00:00
|
|
|
|
1998-12-04 19:26:43 +00:00
|
|
|
m = Py_InitModule3("cmath", cmath_methods, module_doc);
|
2002-04-01 03:45:06 +00:00
|
|
|
|
|
|
|
PyModule_AddObject(m, "pi",
|
|
|
|
PyFloat_FromDouble(atan(1.0) * 4.0));
|
|
|
|
PyModule_AddObject(m, "e", PyFloat_FromDouble(exp(1.0)));
|
1996-01-12 01:34:57 +00:00
|
|
|
}
|