diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index 3ea9e5ba071289..071b90b9359fa5 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -273,9 +273,9 @@ C11 standard) is supported, the following format characters are available: +--------+--------------------------+--------------------+----------------+------------+ | Format | C Type | Python type | Standard size | Notes | +========+==========================+====================+================+============+ -| ``E`` | :c:expr:`float complex` | complex | 8 | \(10) | +| ``F`` | :c:expr:`float complex` | complex | 8 | \(10) | +--------+--------------------------+--------------------+----------------+------------+ -| ``C`` | :c:expr:`double complex` | complex | 16 | \(10) | +| ``D`` | :c:expr:`double complex` | complex | 16 | \(10) | +--------+--------------------------+--------------------+----------------+------------+ .. versionchanged:: 3.3 @@ -285,7 +285,7 @@ C11 standard) is supported, the following format characters are available: Added support for the ``'e'`` format. .. versionchanged:: 3.14 - Added support for the ``'E'`` and ``'C'`` formats. + Added support for the ``'F'`` and ``'D'`` formats. Notes: diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 63a5bab7fe8fea..a9b5e43de91aa2 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1130,7 +1130,7 @@ struct ------ * Support the :c:expr:`float complex` and :c:expr:`double complex` C types in - the :mod:`struct` module (formatting characters ``'E'`` and ``'C'``, + the :mod:`struct` module (formatting characters ``'F'`` and ``'D'``, respectively) if the compiler has C11 complex arithmetic. (Contributed by Sergey B Kirpichev in :gh:`121249`.) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index bba08b99b95b8b..b0e74f679ed18a 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -209,13 +209,13 @@ class c_longdouble(_SimpleCData): try: class c_double_complex(_SimpleCData): - _type_ = "C" + _type_ = "D" _check_size(c_double_complex) class c_float_complex(_SimpleCData): - _type_ = "E" + _type_ = "F" _check_size(c_float_complex) class c_longdouble_complex(_SimpleCData): - _type_ = "F" + _type_ = "G" except AttributeError: pass diff --git a/Lib/test/test_ctypes/test_c_simple_type_meta.py b/Lib/test/test_ctypes/test_c_simple_type_meta.py index b446fd5c77dde2..2328611856a1a0 100644 --- a/Lib/test/test_ctypes/test_c_simple_type_meta.py +++ b/Lib/test/test_ctypes/test_c_simple_type_meta.py @@ -160,11 +160,11 @@ def test_bad_type_message(self): class F(metaclass=PyCSimpleType): _type_ = "\0" message = str(cm.exception) - expected_type_chars = list('cbBhHiIlLdCEFfuzZqQPXOv?g') + expected_type_chars = list('cbBhHiIlLdDFGfuzZqQPXOv?g') if not hasattr(ctypes, 'c_float_complex'): - expected_type_chars.remove('C') - expected_type_chars.remove('E') expected_type_chars.remove('F') + expected_type_chars.remove('D') + expected_type_chars.remove('G') if not MS_WINDOWS: expected_type_chars.remove('X') self.assertIn("'" + ''.join(expected_type_chars) + "'", message) diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index b99391e482ff70..a410fd5a1940d1 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -23,7 +23,7 @@ NAN = float('nan') try: - struct.pack('C', 1j) + struct.pack('D', 1j) have_c_complex = True except struct.error: have_c_complex = False @@ -801,23 +801,23 @@ def test_c_complex_round_trip(self): values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2, -3, INF, -INF, NAN], 2)] for z in values: - for f in ['E', 'C', '>E', '>C', 'F', '>D', 'code) { diff --git a/Modules/_struct.c b/Modules/_struct.c index f04805d9d6d1d7..9910986a39570f 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -913,11 +913,11 @@ static const formatdef native_table[] = { {'f', sizeof(float), FLOAT_ALIGN, nu_float, np_float}, {'d', sizeof(double), DOUBLE_ALIGN, nu_double, np_double}, #ifdef Py_HAVE_C_COMPLEX - {'E', sizeof(float complex), FLOAT_COMPLEX_ALIGN, nu_float_complex, np_float_complex}, - {'C', sizeof(double complex), DOUBLE_COMPLEX_ALIGN, nu_double_complex, np_double_complex}, + {'F', sizeof(float complex), FLOAT_COMPLEX_ALIGN, nu_float_complex, np_float_complex}, + {'D', sizeof(double complex), DOUBLE_COMPLEX_ALIGN, nu_double_complex, np_double_complex}, #else - {'E', 1, 0, nu_complex_stub, np_complex_stub}, - {'C', 1, 0, nu_complex_stub, np_complex_stub}, + {'F', 1, 0, nu_complex_stub, np_complex_stub}, + {'D', 1, 0, nu_complex_stub, np_complex_stub}, #endif {'P', sizeof(void *), VOID_P_ALIGN, nu_void_p, np_void_p}, {0} @@ -1253,11 +1253,11 @@ static formatdef bigendian_table[] = { {'f', 4, 0, bu_float, bp_float}, {'d', 8, 0, bu_double, bp_double}, #ifdef Py_HAVE_C_COMPLEX - {'E', 8, 0, bu_float_complex, bp_float_complex}, - {'C', 16, 0, bu_double_complex, bp_double_complex}, + {'F', 8, 0, bu_float_complex, bp_float_complex}, + {'D', 16, 0, bu_double_complex, bp_double_complex}, #else - {'E', 1, 0, nu_complex_stub, np_complex_stub}, - {'C', 1, 0, nu_complex_stub, np_complex_stub}, + {'F', 1, 0, nu_complex_stub, np_complex_stub}, + {'D', 1, 0, nu_complex_stub, np_complex_stub}, #endif {0} }; @@ -1577,11 +1577,11 @@ static formatdef lilendian_table[] = { {'f', 4, 0, lu_float, lp_float}, {'d', 8, 0, lu_double, lp_double}, #ifdef Py_HAVE_C_COMPLEX - {'E', 8, 0, lu_float_complex, lp_float_complex}, - {'C', 16, 0, lu_double_complex, lp_double_complex}, + {'F', 8, 0, lu_float_complex, lp_float_complex}, + {'D', 16, 0, lu_double_complex, lp_double_complex}, #else - {'E', 1, 0, nu_complex_stub, np_complex_stub}, - {'C', 1, 0, nu_complex_stub, np_complex_stub}, + {'F', 1, 0, nu_complex_stub, np_complex_stub}, + {'D', 1, 0, nu_complex_stub, np_complex_stub}, #endif {0} };