summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-09-03 16:21:29 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2016-09-03 16:21:29 (GMT)
commit7c4e409d075fdb923807513353b18a75a4520eba (patch)
tree465cbd3e01ffeba3a85e6da82d51590fc7a57b7d /Doc
parent2500c9827886fb1826317877aacaef023707349e (diff)
downloadcpython-7c4e409d075fdb923807513353b18a75a4520eba.zip
cpython-7c4e409d075fdb923807513353b18a75a4520eba.tar.gz
cpython-7c4e409d075fdb923807513353b18a75a4520eba.tar.bz2
Issue #11734: Add support for IEEE 754 half-precision floats to the struct module. Original patch by Eli Stevens.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/struct.rst23
1 files changed, 20 insertions, 3 deletions
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
index ae2e38f..7e861fd 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 <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 <half precision 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