diff --git a/Doc/c-api/complex.rst b/Doc/c-api/complex.rst
index d1f5d8eda676ef..16bd79475dc1e6 100644
--- a/Doc/c-api/complex.rst
+++ b/Doc/c-api/complex.rst
@@ -44,36 +44,12 @@ pointers. This is consistent throughout the API.
representation.
-.. c:function:: Py_complex _Py_cr_sum(Py_complex left, double right)
-
- Return the sum of a complex number and a real number, using the C :c:type:`Py_complex`
- representation.
-
- .. versionadded:: 3.14
-
-
.. c:function:: Py_complex _Py_c_diff(Py_complex left, Py_complex right)
Return the difference between two complex numbers, using the C
:c:type:`Py_complex` representation.
-.. c:function:: Py_complex _Py_cr_diff(Py_complex left, double right)
-
- Return the difference between a complex number and a real number, using the C
- :c:type:`Py_complex` representation.
-
- .. versionadded:: 3.14
-
-
-.. c:function:: Py_complex _Py_rc_diff(double left, Py_complex right)
-
- Return the difference between a real number and a complex number, using the C
- :c:type:`Py_complex` representation.
-
- .. versionadded:: 3.14
-
-
.. c:function:: Py_complex _Py_c_neg(Py_complex num)
Return the negation of the complex number *num*, using the C
@@ -86,14 +62,6 @@ pointers. This is consistent throughout the API.
representation.
-.. c:function:: Py_complex _Py_cr_prod(Py_complex left, double right)
-
- Return the product of a complex number and a real number, using the C
- :c:type:`Py_complex` representation.
-
- .. versionadded:: 3.14
-
-
.. c:function:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor)
Return the quotient of two complex numbers, using the C :c:type:`Py_complex`
@@ -103,28 +71,6 @@ pointers. This is consistent throughout the API.
:c:data:`errno` to :c:macro:`!EDOM`.
-.. c:function:: Py_complex _Py_cr_quot(Py_complex dividend, double divisor)
-
- Return the quotient of a complex number and a real number, using the C
- :c:type:`Py_complex` representation.
-
- If *divisor* is zero, this method returns zero and sets
- :c:data:`errno` to :c:macro:`!EDOM`.
-
- .. versionadded:: 3.14
-
-
-.. c:function:: Py_complex _Py_rc_quot(double dividend, Py_complex divisor)
-
- Return the quotient of a real number and a complex number, using the C
- :c:type:`Py_complex` representation.
-
- If *divisor* is zero, this method returns zero and sets
- :c:data:`errno` to :c:macro:`!EDOM`.
-
- .. versionadded:: 3.14
-
-
.. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex`
diff --git a/Include/cpython/complexobject.h b/Include/cpython/complexobject.h
index 28576afad0b6b5..fbdc6a91fe895c 100644
--- a/Include/cpython/complexobject.h
+++ b/Include/cpython/complexobject.h
@@ -9,16 +9,10 @@ typedef struct {
// Operations on complex numbers.
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_cr_sum(Py_complex, double);
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_cr_diff(Py_complex, double);
-PyAPI_FUNC(Py_complex) _Py_rc_diff(double, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_cr_prod(Py_complex, double);
PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_cr_quot(Py_complex, double);
-PyAPI_FUNC(Py_complex) _Py_rc_quot(double, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
PyAPI_FUNC(double) _Py_c_abs(Py_complex);
diff --git a/Include/internal/pycore_complexobject.h b/Include/internal/pycore_complexobject.h
index 54713536eedc46..f595f6ab7a674d 100644
--- a/Include/internal/pycore_complexobject.h
+++ b/Include/internal/pycore_complexobject.h
@@ -19,6 +19,15 @@ extern int _PyComplex_FormatAdvancedWriter(
Py_ssize_t start,
Py_ssize_t end);
+// Operations on complex numbers.
+PyAPI_FUNC(Py_complex) _Py_cr_sum(Py_complex, double);
+PyAPI_FUNC(Py_complex) _Py_cr_diff(Py_complex, double);
+PyAPI_FUNC(Py_complex) _Py_rc_diff(double, Py_complex);
+PyAPI_FUNC(Py_complex) _Py_cr_prod(Py_complex, double);
+PyAPI_FUNC(Py_complex) _Py_cr_quot(Py_complex, double);
+PyAPI_FUNC(Py_complex) _Py_rc_quot(double, Py_complex);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/Lib/test/test_capi/test_complex.py b/Lib/test/test_capi/test_complex.py
index 97e0eb3f043080..c3189a67cc7e2d 100644
--- a/Lib/test/test_capi/test_complex.py
+++ b/Lib/test/test_capi/test_complex.py
@@ -12,6 +12,7 @@
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
+_testinternalcapi = import_helper.import_module('_testinternalcapi')
NULL = None
INF = float("inf")
@@ -174,7 +175,7 @@ def test_py_c_sum(self):
def test_py_cr_sum(self):
# Test _Py_cr_sum()
- _py_cr_sum = _testcapi._py_cr_sum
+ _py_cr_sum = _testinternalcapi._py_cr_sum
self.assertComplexesAreIdentical(_py_cr_sum(-0j, -0.0)[0],
complex(-0.0, -0.0))
@@ -187,14 +188,14 @@ def test_py_c_diff(self):
def test_py_cr_diff(self):
# Test _Py_cr_diff()
- _py_cr_diff = _testcapi._py_cr_diff
+ _py_cr_diff = _testinternalcapi._py_cr_diff
self.assertComplexesAreIdentical(_py_cr_diff(-0j, 0.0)[0],
complex(-0.0, -0.0))
def test_py_rc_diff(self):
# Test _Py_rc_diff()
- _py_rc_diff = _testcapi._py_rc_diff
+ _py_rc_diff = _testinternalcapi._py_rc_diff
self.assertComplexesAreIdentical(_py_rc_diff(-0.0, 0j)[0],
complex(-0.0, -0.0))
@@ -213,7 +214,7 @@ def test_py_c_prod(self):
def test_py_cr_prod(self):
# Test _Py_cr_prod()
- _py_cr_prod = _testcapi._py_cr_prod
+ _py_cr_prod = _testinternalcapi._py_cr_prod
self.assertComplexesAreIdentical(_py_cr_prod(complex('inf+1j'), INF)[0],
complex('inf+infj'))
@@ -242,14 +243,14 @@ def test_py_c_quot(self):
def test_py_cr_quot(self):
# Test _Py_cr_quot()
- _py_cr_quot = _testcapi._py_cr_quot
+ _py_cr_quot = _testinternalcapi._py_cr_quot
self.assertComplexesAreIdentical(_py_cr_quot(complex('inf+1j'), 2**1000)[0],
INF + 2**-1000*1j)
def test_py_rc_quot(self):
# Test _Py_rc_quot()
- _py_rc_quot = _testcapi._py_rc_quot
+ _py_rc_quot = _testinternalcapi._py_rc_quot
self.assertComplexesAreIdentical(_py_rc_quot(1.0, complex('nan-infj'))[0],
0j)
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 6bb05a06a3465d..95696d5f8aeeb4 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -161,7 +161,7 @@
@MODULE_XXSUBTYPE_TRUE@xxsubtype xxsubtype.c
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
-@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
+@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c _testinternalcapi/complex.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c _testcapi/type.c _testcapi/function.c
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
diff --git a/Modules/_testcapi/complex.c b/Modules/_testcapi/complex.c
index b726cd3236f179..fb5234d03cf067 100644
--- a/Modules/_testcapi/complex.c
+++ b/Modules/_testcapi/complex.c
@@ -57,48 +57,10 @@ _py_c_neg(PyObject *Py_UNUSED(module), PyObject *num)
return Py_BuildValue("Di", &res, errno); \
};
-#define _PY_CR_FUNC2(suffix) \
- static PyObject * \
- _py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
- { \
- Py_complex a, res; \
- double b; \
- \
- if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
- return NULL; \
- } \
- \
- errno = 0; \
- res = _Py_cr_##suffix(a, b); \
- return Py_BuildValue("Di", &res, errno); \
- };
-
-#define _PY_RC_FUNC2(suffix) \
- static PyObject * \
- _py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
- { \
- Py_complex b, res; \
- double a; \
- \
- if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
- return NULL; \
- } \
- \
- errno = 0; \
- res = _Py_rc_##suffix(a, b); \
- return Py_BuildValue("Di", &res, errno); \
- };
-
_PY_C_FUNC2(sum)
-_PY_CR_FUNC2(sum)
_PY_C_FUNC2(diff)
-_PY_CR_FUNC2(diff)
-_PY_RC_FUNC2(diff)
_PY_C_FUNC2(prod)
-_PY_CR_FUNC2(prod)
_PY_C_FUNC2(quot)
-_PY_CR_FUNC2(quot)
-_PY_RC_FUNC2(quot)
_PY_C_FUNC2(pow)
static PyObject*
@@ -124,16 +86,10 @@ static PyMethodDef test_methods[] = {
{"complex_fromccomplex", complex_fromccomplex, METH_O},
{"complex_asccomplex", complex_asccomplex, METH_O},
{"_py_c_sum", _py_c_sum, METH_VARARGS},
- {"_py_cr_sum", _py_cr_sum, METH_VARARGS},
{"_py_c_diff", _py_c_diff, METH_VARARGS},
- {"_py_cr_diff", _py_cr_diff, METH_VARARGS},
- {"_py_rc_diff", _py_rc_diff, METH_VARARGS},
{"_py_c_neg", _py_c_neg, METH_O},
{"_py_c_prod", _py_c_prod, METH_VARARGS},
- {"_py_cr_prod", _py_cr_prod, METH_VARARGS},
{"_py_c_quot", _py_c_quot, METH_VARARGS},
- {"_py_cr_quot", _py_cr_quot, METH_VARARGS},
- {"_py_rc_quot", _py_rc_quot, METH_VARARGS},
{"_py_c_pow", _py_c_pow, METH_VARARGS},
{"_py_c_abs", _py_c_abs, METH_O},
{NULL},
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 56e3408652a6a0..00d3f7bb3f6182 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -2118,6 +2118,9 @@ module_exec(PyObject *module)
if (_PyTestInternalCapi_Init_Set(module) < 0) {
return 1;
}
+ if (_PyTestInternalCapi_Init_Complex(module) < 0) {
+ return 1;
+ }
if (_PyTestInternalCapi_Init_CriticalSection(module) < 0) {
return 1;
}
diff --git a/Modules/_testinternalcapi/complex.c b/Modules/_testinternalcapi/complex.c
new file mode 100644
index 00000000000000..50080d5a389ceb
--- /dev/null
+++ b/Modules/_testinternalcapi/complex.c
@@ -0,0 +1,66 @@
+#include "parts.h"
+#include "../_testcapi/util.h"
+
+#define Py_BUILD_CORE
+#include "pycore_complexobject.h"
+
+
+#define _PY_CR_FUNC2(suffix) \
+ static PyObject * \
+ _py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
+ { \
+ Py_complex a, res; \
+ double b; \
+ \
+ if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
+ return NULL; \
+ } \
+ \
+ errno = 0; \
+ res = _Py_cr_##suffix(a, b); \
+ return Py_BuildValue("Di", &res, errno); \
+ };
+
+#define _PY_RC_FUNC2(suffix) \
+ static PyObject * \
+ _py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
+ { \
+ Py_complex b, res; \
+ double a; \
+ \
+ if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
+ return NULL; \
+ } \
+ \
+ errno = 0; \
+ res = _Py_rc_##suffix(a, b); \
+ return Py_BuildValue("Di", &res, errno); \
+ };
+
+_PY_CR_FUNC2(sum)
+_PY_CR_FUNC2(diff)
+_PY_RC_FUNC2(diff)
+_PY_CR_FUNC2(prod)
+_PY_CR_FUNC2(quot)
+_PY_RC_FUNC2(quot)
+
+
+static PyMethodDef test_methods[] = {
+ {"_py_cr_sum", _py_cr_sum, METH_VARARGS},
+ {"_py_cr_diff", _py_cr_diff, METH_VARARGS},
+ {"_py_rc_diff", _py_rc_diff, METH_VARARGS},
+ {"_py_cr_prod", _py_cr_prod, METH_VARARGS},
+ {"_py_cr_quot", _py_cr_quot, METH_VARARGS},
+ {"_py_rc_quot", _py_rc_quot, METH_VARARGS},
+ {NULL},
+};
+
+int
+_PyTestInternalCapi_Init_Complex(PyObject *mod)
+{
+ if (PyModule_AddFunctions(mod, test_methods) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/Modules/_testinternalcapi/parts.h b/Modules/_testinternalcapi/parts.h
index 49a1395f499fc3..03557d5bf5957f 100644
--- a/Modules/_testinternalcapi/parts.h
+++ b/Modules/_testinternalcapi/parts.h
@@ -13,6 +13,7 @@
int _PyTestInternalCapi_Init_Lock(PyObject *module);
int _PyTestInternalCapi_Init_PyTime(PyObject *module);
int _PyTestInternalCapi_Init_Set(PyObject *module);
+int _PyTestInternalCapi_Init_Complex(PyObject *module);
int _PyTestInternalCapi_Init_CriticalSection(PyObject *module);
#endif // Py_TESTINTERNALCAPI_PARTS_H
diff --git a/PCbuild/_testinternalcapi.vcxproj b/PCbuild/_testinternalcapi.vcxproj
index 87db569423de2a..f7e050b7c74180 100644
--- a/PCbuild/_testinternalcapi.vcxproj
+++ b/PCbuild/_testinternalcapi.vcxproj
@@ -98,6 +98,7 @@
+
diff --git a/PCbuild/_testinternalcapi.vcxproj.filters b/PCbuild/_testinternalcapi.vcxproj.filters
index eb0a83ba17f815..012d709bd1ce5d 100644
--- a/PCbuild/_testinternalcapi.vcxproj.filters
+++ b/PCbuild/_testinternalcapi.vcxproj.filters
@@ -24,6 +24,9 @@
Source Files
+
+ Source Files
+