Commit 4288c805 authored by Fred Drake's avatar Fred Drake

ANSI-fication of the sources.

parent 4201b9e4
...@@ -28,8 +28,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. ...@@ -28,8 +28,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
static Py_complex c_1 = {1., 0.}; static Py_complex c_1 = {1., 0.};
Py_complex c_sum(a,b) Py_complex c_sum(Py_complex a, Py_complex b)
Py_complex a,b;
{ {
Py_complex r; Py_complex r;
r.real = a.real + b.real; r.real = a.real + b.real;
...@@ -37,8 +36,7 @@ Py_complex c_sum(a,b) ...@@ -37,8 +36,7 @@ Py_complex c_sum(a,b)
return r; return r;
} }
Py_complex c_diff(a,b) Py_complex c_diff(Py_complex a, Py_complex b)
Py_complex a,b;
{ {
Py_complex r; Py_complex r;
r.real = a.real - b.real; r.real = a.real - b.real;
...@@ -46,8 +44,7 @@ Py_complex c_diff(a,b) ...@@ -46,8 +44,7 @@ Py_complex c_diff(a,b)
return r; return r;
} }
Py_complex c_neg(a) Py_complex c_neg(Py_complex a)
Py_complex a;
{ {
Py_complex r; Py_complex r;
r.real = -a.real; r.real = -a.real;
...@@ -55,8 +52,7 @@ Py_complex c_neg(a) ...@@ -55,8 +52,7 @@ Py_complex c_neg(a)
return r; return r;
} }
Py_complex c_prod(a,b) Py_complex c_prod(Py_complex a, Py_complex b)
Py_complex a,b;
{ {
Py_complex r; Py_complex r;
r.real = a.real*b.real - a.imag*b.imag; r.real = a.real*b.real - a.imag*b.imag;
...@@ -64,8 +60,7 @@ Py_complex c_prod(a,b) ...@@ -64,8 +60,7 @@ Py_complex c_prod(a,b)
return r; return r;
} }
Py_complex c_quot(a,b) Py_complex c_quot(Py_complex a, Py_complex b)
Py_complex a,b;
{ {
Py_complex r; Py_complex r;
double d = b.real*b.real + b.imag*b.imag; double d = b.real*b.real + b.imag*b.imag;
...@@ -76,8 +71,7 @@ Py_complex c_quot(a,b) ...@@ -76,8 +71,7 @@ Py_complex c_quot(a,b)
return r; return r;
} }
Py_complex c_pow(a,b) Py_complex c_pow(Py_complex a, Py_complex b)
Py_complex a,b;
{ {
Py_complex r; Py_complex r;
double vabs,len,at,phase; double vabs,len,at,phase;
...@@ -106,9 +100,7 @@ Py_complex c_pow(a,b) ...@@ -106,9 +100,7 @@ Py_complex c_pow(a,b)
return r; return r;
} }
static Py_complex c_powu(x, n) static Py_complex c_powu(Py_complex x, long n)
Py_complex x;
long n;
{ {
Py_complex r, p; Py_complex r, p;
long mask = 1; long mask = 1;
...@@ -123,9 +115,7 @@ static Py_complex c_powu(x, n) ...@@ -123,9 +115,7 @@ static Py_complex c_powu(x, n)
return r; return r;
} }
static Py_complex c_powi(x, n) static Py_complex c_powi(Py_complex x, long n)
Py_complex x;
long n;
{ {
Py_complex cn; Py_complex cn;
...@@ -142,8 +132,7 @@ static Py_complex c_powi(x, n) ...@@ -142,8 +132,7 @@ static Py_complex c_powi(x, n)
} }
PyObject * PyObject *
PyComplex_FromCComplex(cval) PyComplex_FromCComplex(Py_complex cval)
Py_complex cval;
{ {
register PyComplexObject *op; register PyComplexObject *op;
...@@ -157,8 +146,7 @@ PyComplex_FromCComplex(cval) ...@@ -157,8 +146,7 @@ PyComplex_FromCComplex(cval)
} }
PyObject * PyObject *
PyComplex_FromDoubles(real, imag) PyComplex_FromDoubles(double real, double imag)
double real, imag;
{ {
Py_complex c; Py_complex c;
c.real = real; c.real = real;
...@@ -167,35 +155,35 @@ PyComplex_FromDoubles(real, imag) ...@@ -167,35 +155,35 @@ PyComplex_FromDoubles(real, imag)
} }
double double
PyComplex_RealAsDouble(op) PyComplex_RealAsDouble(PyObject *op)
PyObject *op;
{ {
if (PyComplex_Check(op)) { if (PyComplex_Check(op)) {
return ((PyComplexObject *)op)->cval.real; return ((PyComplexObject *)op)->cval.real;
} else { }
else {
return PyFloat_AsDouble(op); return PyFloat_AsDouble(op);
} }
} }
double double
PyComplex_ImagAsDouble(op) PyComplex_ImagAsDouble(PyObject *op)
PyObject *op;
{ {
if (PyComplex_Check(op)) { if (PyComplex_Check(op)) {
return ((PyComplexObject *)op)->cval.imag; return ((PyComplexObject *)op)->cval.imag;
} else { }
else {
return 0.0; return 0.0;
} }
} }
Py_complex Py_complex
PyComplex_AsCComplex(op) PyComplex_AsCComplex(PyObject *op)
PyObject *op;
{ {
Py_complex cv; Py_complex cv;
if (PyComplex_Check(op)) { if (PyComplex_Check(op)) {
return ((PyComplexObject *)op)->cval; return ((PyComplexObject *)op)->cval;
} else { }
else {
cv.real = PyFloat_AsDouble(op); cv.real = PyFloat_AsDouble(op);
cv.imag = 0.; cv.imag = 0.;
return cv; return cv;
...@@ -203,17 +191,14 @@ PyComplex_AsCComplex(op) ...@@ -203,17 +191,14 @@ PyComplex_AsCComplex(op)
} }
static void static void
complex_dealloc(op) complex_dealloc(PyObject *op)
PyObject *op;
{ {
PyObject_DEL(op); PyObject_DEL(op);
} }
static void static void
complex_buf_repr(buf, v) complex_buf_repr(char *buf, PyComplexObject *v)
char *buf;
PyComplexObject *v;
{ {
if (v->cval.real == 0.) if (v->cval.real == 0.)
sprintf(buf, "%.12gj", v->cval.imag); sprintf(buf, "%.12gj", v->cval.imag);
...@@ -222,10 +207,8 @@ complex_buf_repr(buf, v) ...@@ -222,10 +207,8 @@ complex_buf_repr(buf, v)
} }
static int static int
complex_print(v, fp, flags) complex_print(PyComplexObject *v, FILE *fp, int flags)
PyComplexObject *v; /* flags -- not used but required by interface */
FILE *fp;
int flags; /* Not used but required by interface */
{ {
char buf[100]; char buf[100];
complex_buf_repr(buf, v); complex_buf_repr(buf, v);
...@@ -234,8 +217,7 @@ complex_print(v, fp, flags) ...@@ -234,8 +217,7 @@ complex_print(v, fp, flags)
} }
static PyObject * static PyObject *
complex_repr(v) complex_repr(PyComplexObject *v)
PyComplexObject *v;
{ {
char buf[100]; char buf[100];
complex_buf_repr(buf, v); complex_buf_repr(buf, v);
...@@ -243,25 +225,23 @@ complex_repr(v) ...@@ -243,25 +225,23 @@ complex_repr(v)
} }
static int static int
complex_compare(v, w) complex_compare(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v, *w;
{ {
/* Note: "greater" and "smaller" have no meaning for complex numbers, /* Note: "greater" and "smaller" have no meaning for complex numbers,
but Python requires that they be defined nevertheless. */ but Python requires that they be defined nevertheless. */
Py_complex i, j; Py_complex i, j;
i = v->cval; i = v->cval;
j = w->cval; j = w->cval;
if (i.real == j.real && i.imag == j.imag) if (i.real == j.real && i.imag == j.imag)
return 0; return 0;
else if (i.real != j.real) else if (i.real != j.real)
return (i.real < j.real) ? -1 : 1; return (i.real < j.real) ? -1 : 1;
else else
return (i.imag < j.imag) ? -1 : 1; return (i.imag < j.imag) ? -1 : 1;
} }
static long static long
complex_hash(v) complex_hash(PyComplexObject *v)
PyComplexObject *v;
{ {
double intpart, fractpart; double intpart, fractpart;
long x; long x;
...@@ -312,9 +292,7 @@ complex_hash(v) ...@@ -312,9 +292,7 @@ complex_hash(v)
} }
static PyObject * static PyObject *
complex_add(v, w) complex_add(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex result; Py_complex result;
PyFPE_START_PROTECT("complex_add", return 0) PyFPE_START_PROTECT("complex_add", return 0)
...@@ -324,9 +302,7 @@ complex_add(v, w) ...@@ -324,9 +302,7 @@ complex_add(v, w)
} }
static PyObject * static PyObject *
complex_sub(v, w) complex_sub(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex result; Py_complex result;
PyFPE_START_PROTECT("complex_sub", return 0) PyFPE_START_PROTECT("complex_sub", return 0)
...@@ -336,9 +312,7 @@ complex_sub(v, w) ...@@ -336,9 +312,7 @@ complex_sub(v, w)
} }
static PyObject * static PyObject *
complex_mul(v, w) complex_mul(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex result; Py_complex result;
PyFPE_START_PROTECT("complex_mul", return 0) PyFPE_START_PROTECT("complex_mul", return 0)
...@@ -348,9 +322,7 @@ complex_mul(v, w) ...@@ -348,9 +322,7 @@ complex_mul(v, w)
} }
static PyObject * static PyObject *
complex_div(v, w) complex_div(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex quot; Py_complex quot;
PyFPE_START_PROTECT("complex_div", return 0) PyFPE_START_PROTECT("complex_div", return 0)
...@@ -365,9 +337,7 @@ complex_div(v, w) ...@@ -365,9 +337,7 @@ complex_div(v, w)
} }
static PyObject * static PyObject *
complex_remainder(v, w) complex_remainder(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex div, mod; Py_complex div, mod;
errno = 0; errno = 0;
...@@ -385,9 +355,7 @@ complex_remainder(v, w) ...@@ -385,9 +355,7 @@ complex_remainder(v, w)
static PyObject * static PyObject *
complex_divmod(v, w) complex_divmod(PyComplexObject *v, PyComplexObject *w)
PyComplexObject *v;
PyComplexObject *w;
{ {
Py_complex div, mod; Py_complex div, mod;
PyObject *d, *m, *z; PyObject *d, *m, *z;
...@@ -409,10 +377,7 @@ complex_divmod(v, w) ...@@ -409,10 +377,7 @@ complex_divmod(v, w)
} }
static PyObject * static PyObject *
complex_pow(v, w, z) complex_pow(PyComplexObject *v, PyObject *w, PyComplexObject *z)
PyComplexObject *v;
PyObject *w;
PyComplexObject *z;
{ {
Py_complex p; Py_complex p;
Py_complex exponent; Py_complex exponent;
...@@ -422,7 +387,6 @@ complex_pow(v, w, z) ...@@ -422,7 +387,6 @@ complex_pow(v, w, z)
PyErr_SetString(PyExc_ValueError, "complex modulo"); PyErr_SetString(PyExc_ValueError, "complex modulo");
return NULL; return NULL;
} }
PyFPE_START_PROTECT("complex_pow", return 0) PyFPE_START_PROTECT("complex_pow", return 0)
errno = 0; errno = 0;
exponent = ((PyComplexObject*)w)->cval; exponent = ((PyComplexObject*)w)->cval;
...@@ -438,13 +402,11 @@ complex_pow(v, w, z) ...@@ -438,13 +402,11 @@ complex_pow(v, w, z)
"0.0 to a negative or complex power"); "0.0 to a negative or complex power");
return NULL; return NULL;
} }
return PyComplex_FromCComplex(p); return PyComplex_FromCComplex(p);
} }
static PyObject * static PyObject *
complex_neg(v) complex_neg(PyComplexObject *v)
PyComplexObject *v;
{ {
Py_complex neg; Py_complex neg;
neg.real = -v->cval.real; neg.real = -v->cval.real;
...@@ -453,16 +415,14 @@ complex_neg(v) ...@@ -453,16 +415,14 @@ complex_neg(v)
} }
static PyObject * static PyObject *
complex_pos(v) complex_pos(PyComplexObject *v)
PyComplexObject *v;
{ {
Py_INCREF(v); Py_INCREF(v);
return (PyObject *)v; return (PyObject *)v;
} }
static PyObject * static PyObject *
complex_abs(v) complex_abs(PyComplexObject *v)
PyComplexObject *v;
{ {
double result; double result;
PyFPE_START_PROTECT("complex_abs", return 0) PyFPE_START_PROTECT("complex_abs", return 0)
...@@ -472,16 +432,13 @@ complex_abs(v) ...@@ -472,16 +432,13 @@ complex_abs(v)
} }
static int static int
complex_nonzero(v) complex_nonzero(PyComplexObject *v)
PyComplexObject *v;
{ {
return v->cval.real != 0.0 || v->cval.imag != 0.0; return v->cval.real != 0.0 || v->cval.imag != 0.0;
} }
static int static int
complex_coerce(pv, pw) complex_coerce(PyObject **pv, PyObject **pw)
PyObject **pv;
PyObject **pw;
{ {
Py_complex cval; Py_complex cval;
cval.imag = 0.; cval.imag = 0.;
...@@ -507,8 +464,7 @@ complex_coerce(pv, pw) ...@@ -507,8 +464,7 @@ complex_coerce(pv, pw)
} }
static PyObject * static PyObject *
complex_int(v) complex_int(PyObject *v)
PyObject *v;
{ {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"can't convert complex to int; use e.g. int(abs(z))"); "can't convert complex to int; use e.g. int(abs(z))");
...@@ -516,8 +472,7 @@ complex_int(v) ...@@ -516,8 +472,7 @@ complex_int(v)
} }
static PyObject * static PyObject *
complex_long(v) complex_long(PyObject *v)
PyObject *v;
{ {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"can't convert complex to long; use e.g. long(abs(z))"); "can't convert complex to long; use e.g. long(abs(z))");
...@@ -525,8 +480,7 @@ complex_long(v) ...@@ -525,8 +480,7 @@ complex_long(v)
} }
static PyObject * static PyObject *
complex_float(v) complex_float(PyObject *v)
PyObject *v;
{ {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"can't convert complex to float; use e.g. abs(z)"); "can't convert complex to float; use e.g. abs(z)");
...@@ -534,9 +488,7 @@ complex_float(v) ...@@ -534,9 +488,7 @@ complex_float(v)
} }
static PyObject * static PyObject *
complex_conjugate(self, args) complex_conjugate(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
Py_complex c; Py_complex c;
if (!PyArg_ParseTuple(args, ":conjugate")) if (!PyArg_ParseTuple(args, ":conjugate"))
...@@ -553,9 +505,7 @@ static PyMethodDef complex_methods[] = { ...@@ -553,9 +505,7 @@ static PyMethodDef complex_methods[] = {
static PyObject * static PyObject *
complex_getattr(self, name) complex_getattr(PyComplexObject *self, char *name)
PyComplexObject *self;
char *name;
{ {
if (strcmp(name, "real") == 0) if (strcmp(name, "real") == 0)
return (PyObject *)PyFloat_FromDouble(self->cval.real); return (PyObject *)PyFloat_FromDouble(self->cval.real);
......
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