Skip to content

Commit badf492

Browse files
committed
address review:
* macro formatting * macro params * check if some argument of complex_##NAME is a complex
1 parent 7fb1be1 commit badf492

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

Objects/complexobject.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -621,39 +621,42 @@ real_to_complex(PyObject **pobj, Py_complex *pc)
621621
See C11's Annex G, sections G.5.1 and G.5.2.
622622
*/
623623

624-
#define COMPLEX_BINOP(name, func) \
625-
static PyObject * \
626-
complex_##name(PyObject *v, PyObject *w) \
627-
{ \
628-
Py_complex a; \
629-
errno = 0; \
630-
if (PyComplex_Check(w)) { \
631-
Py_complex b = ((PyComplexObject *)(w))->cval; \
632-
if (PyComplex_Check(v)) { \
633-
a = ((PyComplexObject *)(v))->cval; \
634-
a = _Py_c_##func(a, b); \
635-
} \
636-
else if (real_to_double(&v, &a.real) < 0) { \
637-
return v; \
638-
} \
639-
else { \
640-
a = _Py_rc_##func(a.real, b); \
641-
} \
642-
} \
643-
else { \
644-
a = ((PyComplexObject *)(v))->cval; \
645-
double b; \
646-
if (real_to_double(&w, &b) < 0) { \
647-
return w; \
648-
} \
649-
a = _Py_cr_##func(a, b); \
650-
} \
651-
if (errno == EDOM) { \
652-
PyErr_SetString(PyExc_ZeroDivisionError, \
653-
"division by zero"); \
654-
return NULL; \
655-
} \
656-
return PyComplex_FromCComplex(a); \
624+
#define COMPLEX_BINOP(NAME, FUNC) \
625+
static PyObject * \
626+
complex_##NAME(PyObject *v, PyObject *w) \
627+
{ \
628+
Py_complex a; \
629+
errno = 0; \
630+
if (PyComplex_Check(w)) { \
631+
Py_complex b = ((PyComplexObject *)w)->cval; \
632+
if (PyComplex_Check(v)) { \
633+
a = ((PyComplexObject *)(v))->cval; \
634+
a = _Py_c_##FUNC(a, b); \
635+
} \
636+
else if (real_to_double(&v, &a.real) < 0) { \
637+
return v; \
638+
} \
639+
else { \
640+
a = _Py_rc_##FUNC(a.real, b); \
641+
} \
642+
} \
643+
else if (!PyComplex_Check(v)) { \
644+
Py_RETURN_NOTIMPLEMENTED; \
645+
} \
646+
else { \
647+
a = ((PyComplexObject *)v)->cval; \
648+
double b; \
649+
if (real_to_double(&w, &b) < 0) { \
650+
return w; \
651+
} \
652+
a = _Py_cr_##FUNC(a, b); \
653+
} \
654+
if (errno == EDOM) { \
655+
PyErr_SetString(PyExc_ZeroDivisionError, \
656+
"division by zero"); \
657+
return NULL; \
658+
} \
659+
return PyComplex_FromCComplex(a); \
657660
}
658661

659662
COMPLEX_BINOP(add, sum)

0 commit comments

Comments
 (0)