Commit 926518b6 authored by Guido van Rossum's avatar Guido van Rossum

Changes to make the file acceptable to K&R C compilers (HPUX, SunOS 4.x).

parent bf05d4cd
...@@ -140,9 +140,10 @@ static Py_complex c_powu(x, n) ...@@ -140,9 +140,10 @@ static Py_complex c_powu(x, n)
Py_complex x; Py_complex x;
long n; long n;
{ {
Py_complex r = c_1; Py_complex r, p;
Py_complex p = x;
long mask = 1; long mask = 1;
r = c_1;
p = x;
while (mask > 0 && n >= mask) { while (mask > 0 && n >= mask) {
if (n & mask) if (n & mask)
r = c_prod(r,p); r = c_prod(r,p);
...@@ -171,9 +172,11 @@ static Py_complex c_powi(x, n) ...@@ -171,9 +172,11 @@ static Py_complex c_powi(x, n)
} }
PyObject * PyObject *
PyComplex_FromCComplex(Py_complex cval) PyComplex_FromCComplex(cval)
Py_complex cval;
{ {
register complexobject *op = (complexobject *) malloc(sizeof(complexobject)); register complexobject *op =
(complexobject *) malloc(sizeof(complexobject));
if (op == NULL) if (op == NULL)
return err_nomem(); return err_nomem();
op->ob_type = &Complextype; op->ob_type = &Complextype;
...@@ -183,33 +186,41 @@ PyComplex_FromCComplex(Py_complex cval) ...@@ -183,33 +186,41 @@ PyComplex_FromCComplex(Py_complex cval)
} }
PyObject * PyObject *
PyComplex_FromDoubles(double real, double imag) { PyComplex_FromDoubles(real, imag)
Py_complex c; double real, imag;
c.real = real; {
c.imag = imag; Py_complex c;
return PyComplex_FromCComplex(c); c.real = real;
c.imag = imag;
return PyComplex_FromCComplex(c);
} }
double double
PyComplex_RealAsDouble(PyObject *op) { PyComplex_RealAsDouble(op)
if (PyComplex_Check(op)) { PyObject *op;
return ((PyComplexObject *)op)->cval.real; {
} else { if (PyComplex_Check(op)) {
return PyFloat_AsDouble(op); return ((PyComplexObject *)op)->cval.real;
} } else {
return PyFloat_AsDouble(op);
}
} }
double double
PyComplex_ImagAsDouble(PyObject *op) { PyComplex_ImagAsDouble(op)
if (PyComplex_Check(op)) { PyObject *op;
return ((PyComplexObject *)op)->cval.imag; {
} else { if (PyComplex_Check(op)) {
return 0.0; return ((PyComplexObject *)op)->cval.imag;
} } else {
return 0.0;
}
} }
Py_complex Py_complex
PyComplex_AsCComplex(PyObject *op) { PyComplex_AsCComplex(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;
...@@ -266,8 +277,9 @@ complex_compare(v, w) ...@@ -266,8 +277,9 @@ complex_compare(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 = v->cval; Py_complex i, j;
Py_complex j = w->cval; i = v->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)
...@@ -497,7 +509,8 @@ static object * ...@@ -497,7 +509,8 @@ static object *
complex_conjugate(self) complex_conjugate(self)
object *self; object *self;
{ {
Py_complex c = ((complexobject *)self)->cval; Py_complex c;
c = ((complexobject *)self)->cval;
c.imag = -c.imag; c.imag = -c.imag;
return newcomplexobject(c); return newcomplexobject(c);
} }
......
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