+-----------+--------------------+-------------------+-----------------------+-------+
| ``'d'`` | double | float | 8 | |
+-----------+--------------------+-------------------+-----------------------+-------+
-| ``'F'`` | float complex | complex | 8 | \(4) |
-+-----------+--------------------+-------------------+-----------------------+-------+
-| ``'D'`` | double complex | complex | 16 | \(4) |
-+-----------+--------------------+-------------------+-----------------------+-------+
| ``'Zf'`` | float complex | complex | 8 | \(4) |
+-----------+--------------------+-------------------+-----------------------+-------+
| ``'Zd'`` | double complex | complex | 16 | \(4) |
.. versionadded:: 3.15
(4)
- Complex types (``F``, ``D``, ``Zf`` and ``Zd``) are available unconditionally,
+ Complex types (``Zf`` and ``Zd``) are available unconditionally,
regardless on support for complex types (the Annex G of the C11 standard)
by the C compiler.
As specified in the C11 standard, each complex type is represented by a
(Contributed by James Hilton-Balfe in :gh:`128335`.)
* The class :class:`memoryview` now supports the :c:expr:`float complex` and
- :c:expr:`double complex` C types: formatting characters ``'F'``/``'Zf'``
- and ``'D'``/``'Zd'`` respectively.
+ :c:expr:`double complex` C types: formatting characters ``'Zf'`` and ``'Zd'``
+ respectively.
(Contributed by Victor Stinner in :gh:`146151` and :gh:`148675`.)
* Allow the *count* argument of :meth:`bytes.replace` to be a keyword.
-----
* Support the :c:expr:`float complex` and :c:expr:`double complex` C types:
- formatting characters ``'F'``/``'Zf'`` and ``'D'``/``'Zd'`` respectively.
+ formatting characters ``'Zf'`` and ``'Zd'`` respectively.
(Contributed by Victor Stinner in :gh:`146151` and :gh:`148675`.)
* Support half-floats (16-bit IEEE 754 binary interchange format): formatting
typecodes = (
'u', 'w', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L',
- 'f', 'd', 'q', 'Q', 'F', 'D', 'e', 'Zf', 'Zd')
+ 'f', 'd', 'q', 'Q', 'e', 'Zf', 'Zd')
class MiscTest(unittest.TestCase):
[9006104071832581.0, float('inf'), float('-inf'), -0.0]),
(['d'], IEEE_754_DOUBLE_BE, '>dddd',
[9006104071832581.0, float('inf'), float('-inf'), -0.0]),
- (['F'], IEEE_754_FLOAT_COMPLEX_LE, '<FFFF',
- [16711938.0j, float('inf'), complex('1-infj'), -0.0]),
- (['F'], IEEE_754_FLOAT_COMPLEX_BE, '>FFFF',
- [16711938.0j, float('inf'), complex('1-infj'), -0.0]),
- (['D'], IEEE_754_DOUBLE_COMPLEX_LE, '<DDDD',
- [9006104071832581.0j, float('inf'), complex('1-infj'), -0.0]),
- (['D'], IEEE_754_DOUBLE_COMPLEX_BE, '>DDDD',
- [9006104071832581.0j, float('inf'), complex('1-infj'), -0.0]),
(['Zf'], IEEE_754_FLOAT_COMPLEX_LE, '<ZfZfZfZf',
[16711938.0j, float('inf'), complex('1-infj'), -0.0]),
(['Zf'], IEEE_754_FLOAT_COMPLEX_BE, '>ZfZfZfZf',
class ComplexFloatTest(CFPTest, unittest.TestCase):
- typecode = 'F'
- minitemsize = 8
-
-class ComplexDoubleTest(CFPTest, unittest.TestCase):
- typecode = 'D'
- minitemsize = 16
-
-class ComplexZfFloatTest(CFPTest, unittest.TestCase):
typecode = 'Zf'
minitemsize = 8
-class ComplexZdDoubleTest(CFPTest, unittest.TestCase):
+class ComplexDoubleTest(CFPTest, unittest.TestCase):
typecode = 'Zd'
minitemsize = 16
'h':0, 'H':0, 'i':0, 'I':0,
'l':0, 'L':0, 'n':0, 'N':0,
'e':0, 'f':0, 'd':0, 'P':0,
- 'F':0, 'D':0, 'Zf':0, 'Zd':0,
+ 'Zf':0, 'Zd':0,
}
# NumPy does not have 'n' or 'N':
'q':(-(1<<63), 1<<63), 'Q':(0, 1<<64),
'e':(-65519, 65520), 'f':(-(1<<63), 1<<63),
'd':(-(1<<1023), 1<<1023),
- 'F':(-(1<<63), 1<<63),
- 'D':(-(1<<1023), 1<<1023),
'Zf':(-(1<<63), 1<<63),
'Zd':(-(1<<1023), 1<<1023),
}
lh = (-(1<<63), 1<<63)
elif fmt == 'd':
lh = (-(1<<1023), 1<<1023)
- elif fmt in ('F', 'Zf'):
+ elif fmt == 'Zf':
lh = (-(1<<63), 1<<63)
- elif fmt in ('D', 'Zd'):
+ elif fmt == 'Zd':
lh = (-(1<<1023), 1<<1023)
else:
for exp in (128, 127, 64, 63, 32, 31, 16, 15, 8, 7):
if char in 'efd':
x = struct.pack(char, x)
x = struct.unpack(char, x)[0]
- if char in ('F', 'D', 'Zf', 'Zd'):
+ if char in ('Zf', 'Zd'):
y = randrange(*fmtdict[mode][char])
x = complex(x, y)
x = struct.pack(char, x)
continue
m2 = m1.cast(fmt)
lo, hi = _range
- if fmt in ("d", "f", "D", "F", "Zd", "Zf"):
+ if fmt in ("d", "f", "Zd", "Zf"):
lo, hi = -2**1024, 2**1024
if fmt != 'P': # PyLong_AsVoidPtr() accepts negative numbers
self.assertRaises(ValueError, m2.__setitem__, 0, lo-1)
check_equal(m, True)
# Test complex formats
- for complex_format in ('F', 'D', 'Zf', 'Zd'):
+ for complex_format in ('Zf', 'Zd'):
with self.subTest(format=complex_format):
data = struct.pack(complex_format * 3, 1.0, 2.0, float('nan'))
m = memoryview(data).cast(complex_format)
def test_complex_types(self):
float_complex_data = struct.pack('FFF', 0.0, -1.5j, 1+2j)
double_complex_data = struct.pack('DDD', 0.0, -1.5j, 1+2j)
- float_complex_view = memoryview(float_complex_data).cast('F')
- double_complex_view = memoryview(double_complex_data).cast('D')
- self.assertEqual(float_complex_view.nbytes * 2, double_complex_view.nbytes)
- self.assertListEqual(float_complex_view.tolist(), double_complex_view.tolist())
float_complex_view = memoryview(float_complex_data).cast('Zf')
double_complex_view = memoryview(double_complex_data).cast('Zd')
self.assertEqual(float_complex_view.nbytes * 2, double_complex_view.nbytes)
--- /dev/null
+Remove ``F`` and ``D`` formats from :mod:`array` and :class:`memoryview`.
+Patch by Victor Stinner.
{"e", sizeof(short), e_getitem, e_setitem, NULL, 0, 0},
{"f", sizeof(float), f_getitem, f_setitem, NULL, 0, 0},
{"d", sizeof(double), d_getitem, d_setitem, NULL, 0, 0},
- {"F", 2*sizeof(float), cf_getitem, cf_setitem, NULL, 0, 0},
- {"D", 2*sizeof(double), cd_getitem, cd_setitem, NULL, 0, 0},
{"Zf", 2*sizeof(float), cf_getitem, cf_setitem, NULL, 0, 0},
{"Zd", 2*sizeof(double), cd_getitem, cd_setitem, NULL, 0, 0},
{NULL, 0, 0, 0, 0, 0, 0} /* Sentinel */
}
break;
case 8:
- if (strcmp(self->ob_descr->typecode, "F") != 0
- && strcmp(self->ob_descr->typecode, "Zf") != 0)
- {
+ if (strcmp(self->ob_descr->typecode, "Zf") != 0) {
for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 8) {
char p0 = p[0];
char p1 = p[1];
}
break;
case 16:
- assert(strcmp(self->ob_descr->typecode, "D") == 0
- || strcmp(self->ob_descr->typecode, "Zd") == 0);
+ assert(strcmp(self->ob_descr->typecode, "Zd") == 0);
for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 8) {
char t0 = p[0];
char t1 = p[1];
case 'd':
return _PY_FLOAT_BIG_ENDIAN ? IEEE_754_DOUBLE_BE : IEEE_754_DOUBLE_LE;
- case 'F':
- return _PY_FLOAT_BIG_ENDIAN ? \
- IEEE_754_FLOAT_COMPLEX_BE : IEEE_754_FLOAT_COMPLEX_LE;
-
- case 'D':
- return _PY_FLOAT_BIG_ENDIAN ? \
- IEEE_754_DOUBLE_COMPLEX_BE : IEEE_754_DOUBLE_COMPLEX_LE;
-
case 'Z': {
switch (typecode[1]) {
case 'f':
}
Py_XDECREF(it);
PyErr_SetString(PyExc_ValueError,
- "bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, e, f, d, F, D, Zf or Zd)");
+ "bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, e, f, d, Zf or Zd)");
return NULL;
}
'e' 16-bit IEEE floats 2\n\
'f' floating-point 4\n\
'd' floating-point 8\n\
- 'F' float complex 8\n\
- 'D' double complex 16\n\
'Zf' float complex 8\n\
'Zd' double complex 16\n\
\n\
case 'f': size = sizeof(float); break;
case 'd': size = sizeof(double); break;
case 'e': size = sizeof(float) / 2; break;
- case 'F': size = 2*sizeof(float); break;
- case 'D': size = 2*sizeof(double); break;
case '?': size = sizeof(_Bool); break;
case 'P': size = sizeof(void *); break;
case 'Z': {
case 'f': RETURN("f");
case 'd': RETURN("d");
case 'e': RETURN("e");
- case 'F': RETURN("F");
- case 'D': RETURN("D");
case 'Z': {
switch (fmt[1]) {
case 'f': RETURN("Zf");
case 'e': d[0] = PyFloat_Unpack2(ptr, endian); goto convert_double;
/* complexes */
- case 'F':
- d[0] = PyFloat_Unpack4(ptr, endian);
- d[1] = PyFloat_Unpack4(ptr + sizeof(float), endian);
- goto convert_double_complex;
-
- case 'D':
- d[0] = PyFloat_Unpack8(ptr, endian);
- d[1] = PyFloat_Unpack8(ptr + sizeof(double), endian);
- goto convert_double_complex;
-
case 'Z': {
switch (fmt[1]) {
case 'f':
break;
/* complexes */
- case 'F': case 'D':
- c = PyComplex_AsCComplex(item);
- if (c.real == -1.0 && PyErr_Occurred()) {
- goto err_occurred;
- }
- CHECK_RELEASED_INT_AGAIN(self);
- if (fmt[0] == 'D') {
- double x[2] = {c.real, c.imag};
-
- memcpy(ptr, &x, sizeof(x));
- }
- else {
- float x[2] = {(float)c.real, (float)c.imag};
-
- memcpy(ptr, &x, sizeof(x));
- }
- break;
-
case 'Z': {
switch (fmt[1]) {
case 'f': case 'd':
}
/* complexes */
- case 'F':
- {
- float x[2], y[2];
-
- memcpy(&x, p, sizeof(x));
- memcpy(&y, q, sizeof(y));
- return (x[0] == y[0]) && (x[1] == y[1]);
- }
- case 'D':
- {
- double x[2], y[2];
-
- memcpy(&x, p, sizeof(x));
- memcpy(&y, q, sizeof(y));
- return (x[0] == y[0]) && (x[1] == y[1]);
- }
case 'Z': {
switch (fmt[1]) {
case 'f':