mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)
"Generally, mixed-mode arithmetic combining real and complex variables should be performed directly, not by first coercing the real to complex, lest the sign of zero be rendered uninformative; the same goes for combinations of pure imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for complex elementary functions. This patch implements mixed-mode arithmetic rules, combining real and complex variables as specified by C standards since C99 (in particular, there is no special version for the true division with real lhs operand). Most C compilers implementing C99+ Annex G have only these special rules (without support for imaginary type, which is going to be deprecated in C2y).
This commit is contained in:
parent
dcf629213b
commit
987311d42e
15 changed files with 449 additions and 98 deletions
|
|
@ -341,16 +341,16 @@ PyFloat_AsDouble(PyObject *op)
|
|||
obj is not of float or int type, Py_NotImplemented is incref'ed,
|
||||
stored in obj, and returned from the function invoking this macro.
|
||||
*/
|
||||
#define CONVERT_TO_DOUBLE(obj, dbl) \
|
||||
if (PyFloat_Check(obj)) \
|
||||
dbl = PyFloat_AS_DOUBLE(obj); \
|
||||
else if (convert_to_double(&(obj), &(dbl)) < 0) \
|
||||
#define CONVERT_TO_DOUBLE(obj, dbl) \
|
||||
if (PyFloat_Check(obj)) \
|
||||
dbl = PyFloat_AS_DOUBLE(obj); \
|
||||
else if (_Py_convert_int_to_double(&(obj), &(dbl)) < 0) \
|
||||
return obj;
|
||||
|
||||
/* Methods */
|
||||
|
||||
static int
|
||||
convert_to_double(PyObject **v, double *dbl)
|
||||
int
|
||||
_Py_convert_int_to_double(PyObject **v, double *dbl)
|
||||
{
|
||||
PyObject *obj = *v;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue