From 0a6df009f15614433b04a5640f5167a1d99245ff Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sat, 3 Sep 2016 17:21:29 +0100 Subject: Issue #11734: Add support for IEEE 754 half-precision floats to the struct module. Original patch by Eli Stevens. --- Doc/library/struct.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'Doc/library/struct.rst') diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index ae2e38fdc0..7e861fdeaf 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -216,6 +216,8 @@ platform-dependent. +--------+--------------------------+--------------------+----------------+------------+ | ``N`` | :c:type:`size_t` | integer | | \(4) | +--------+--------------------------+--------------------+----------------+------------+ +| ``e`` | \(7) | float | 2 | \(5) | ++--------+--------------------------+--------------------+----------------+------------+ | ``f`` | :c:type:`float` | float | 4 | \(5) | +--------+--------------------------+--------------------+----------------+------------+ | ``d`` | :c:type:`double` | float | 8 | \(5) | @@ -257,9 +259,10 @@ Notes: fits your application. (5) - For the ``'f'`` and ``'d'`` conversion codes, the packed representation uses - the IEEE 754 binary32 (for ``'f'``) or binary64 (for ``'d'``) format, - regardless of the floating-point format used by the platform. + For the ``'f'``, ``'d'`` and ``'e'`` conversion codes, the packed + representation uses the IEEE 754 binary32, binary64 or binary16 format (for + ``'f'``, ``'d'`` or ``'e'`` respectively), regardless of the floating-point + format used by the platform. (6) The ``'P'`` format character is only available for the native byte ordering @@ -268,6 +271,16 @@ Notes: on the host system. The struct module does not interpret this as native ordering, so the ``'P'`` format is not available. +(7) + The IEEE 754 binary16 "half precision" type was introduced in the 2008 + revision of the `IEEE 754 standard `_. It has a sign + bit, a 5-bit exponent and 11-bit precision (with 10 bits explicitly stored), + and can represent numbers between approximately ``6.1e-05`` and ``6.5e+04`` + at full precision. This type is not widely supported by C compilers: on a + typical machine, an unsigned short can be used for storage, but not for math + operations. See the Wikipedia page on the `half-precision floating-point + format `_ for more information. + A format character may be preceded by an integral repeat count. For example, the format string ``'4h'`` means exactly the same as ``'hhhh'``. @@ -430,3 +443,7 @@ The :mod:`struct` module also defines the following type: The calculated size of the struct (and hence of the bytes object produced by the :meth:`pack` method) corresponding to :attr:`format`. + +.. _half precision format: https://en.wikipedia.org/wiki/Half-precision_floating-point_format + +.. _ieee 754 standard: https://en.wikipedia.org/wiki/IEEE_floating_point#IEEE_754-2008 -- cgit v1.2.1 From c226dd7ac7a1fc057f630c0276437dcb7617fa84 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 10 Nov 2016 13:25:26 -0500 Subject: Issue #28635: Fix a couple of missing/incorrect versionchanged tags Patch by Elvis Pranskevichus. --- Doc/library/struct.rst | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Doc/library/struct.rst') diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index 7e861fdeaf..cc3017b5fc 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -232,6 +232,10 @@ platform-dependent. .. versionchanged:: 3.3 Added support for the ``'n'`` and ``'N'`` formats. +.. versionchanged:: 3.6 + Added support for the ``'e'`` format. + + Notes: (1) -- cgit v1.2.1