-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
gh-145633: amend dae85c4d939 (refine notes on non-IEEE platforms) #145845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skirpichev
wants to merge
7
commits into
python:main
Choose a base branch
from
skirpichev:dae85c4d939-amend-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−21
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70f72fb
gh-145633: amend dae85c4d939 (refine notes on non-IEEE platforms)
skirpichev 11e9292
-PY_LITTLE_ENDIAN from ignored_c_api.txt
skirpichev 14f9f5c
+1
skirpichev 9124afb
+ changes from #140989
skirpichev c525e92
-Doc/c-api/float.rst
skirpichev 83b7adb
Apply suggestions from code review
skirpichev 15c6b2b
Apply suggestions from code review
skirpichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,22 +192,21 @@ string from a C :c:expr:`double`, and the Unpack routines produce a C | |
| :c:expr:`double` from such a bytes string. The suffix (2, 4 or 8) specifies the | ||
| number of bytes in the bytes string. | ||
|
|
||
| On platforms that appear to use IEEE 754 formats these functions work by | ||
| copying bits. On other platforms, the 2-byte format is identical to the IEEE | ||
| 754 binary16 half-precision format, the 4-byte format (32-bit) is identical to | ||
| the IEEE 754 binary32 single precision format, and the 8-byte format to the | ||
| IEEE 754 binary64 double precision format, although the packing of INFs and | ||
| NaNs (if such things exist on the platform) isn't handled correctly, and | ||
| attempting to unpack a bytes string containing an IEEE INF or NaN will raise an | ||
| exception. | ||
|
|
||
| Note that NaNs type may not be preserved on IEEE platforms (signaling NaN become | ||
| quiet NaN), for example on x86 systems in 32-bit mode. | ||
| * The 2-byte format is the IEEE 754 binary16 half-precision format. | ||
| * The 4-byte format is the IEEE 754 binary32 single-precision format. | ||
| * The 8-byte format is the IEEE 754 binary64 double-precision format. | ||
|
|
||
| The NaN type may not be preserved on some platforms while unpacking (signaling | ||
| NaNs become quiet NaNs), for example on x86 systems in 32-bit mode. | ||
|
|
||
| It's assumed that the :c:expr:`double` type has the IEEE 754 binary64 double | ||
| precision format. What happens if it's not true is partly accidental (alas). | ||
| On non-IEEE platforms with more precision, or larger dynamic range, than IEEE | ||
| 754 supports, not all values can be packed; on non-IEEE platforms with less | ||
| precision, or smaller dynamic range, not all values can be unpacked. What | ||
| happens in such cases is partly accidental (alas). | ||
| precision, or smaller dynamic range, not all values can be unpacked. The | ||
| packing of special numbers like INFs and NaNs (if such things exist on the | ||
| platform) may not be handled correctly, and attempting to unpack a bytes string | ||
| containing an IEEE INF or NaN may raise an exception. | ||
|
|
||
| .. versionadded:: 3.11 | ||
|
|
||
|
|
@@ -216,14 +215,17 @@ Pack functions | |
|
|
||
| The pack routines write 2, 4 or 8 bytes, starting at *p*. *le* is an | ||
| :c:expr:`int` argument, non-zero if you want the bytes string in little-endian | ||
| format (exponent last, at ``p+1``, ``p+3``, or ``p+6`` ``p+7``), zero if you | ||
| want big-endian format (exponent first, at *p*). The :c:macro:`PY_BIG_ENDIAN` | ||
| constant can be used to use the native endian: it is equal to ``1`` on big | ||
| endian processor, or ``0`` on little endian processor. | ||
| format (exponent last, at ``p+1``, ``p+3``, or ``p+6`` and ``p+7``), zero if you | ||
| want big-endian format (exponent first, at *p*). Use the :c:macro:`!PY_LITTLE_ENDIAN` | ||
| constant to select the native endian: it is equal to ``0`` on big | ||
| endian processor, or ``1`` on little endian processor. | ||
|
|
||
| Return value: ``0`` if all is OK, ``-1`` if error (and an exception is set, | ||
| most likely :exc:`OverflowError`). | ||
|
|
||
| .. impl-detail:: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be under |
||
| The :c:func:`PyFloat_Pack8` function always succeeds in CPython. | ||
|
|
||
| .. c:function:: int PyFloat_Pack2(double x, char *p, int le) | ||
|
|
||
| Pack a C double as the IEEE 754 binary16 half-precision format. | ||
|
|
@@ -243,14 +245,17 @@ Unpack functions | |
| The unpack routines read 2, 4 or 8 bytes, starting at *p*. *le* is an | ||
| :c:expr:`int` argument, non-zero if the bytes string is in little-endian format | ||
| (exponent last, at ``p+1``, ``p+3`` or ``p+6`` and ``p+7``), zero if big-endian | ||
| (exponent first, at *p*). The :c:macro:`PY_BIG_ENDIAN` constant can be used to | ||
| use the native endian: it is equal to ``1`` on big endian processor, or ``0`` | ||
| (exponent first, at *p*). Use the :c:macro:`!PY_LITTLE_ENDIAN` constant to | ||
| select the native endian: it is equal to ``0`` on big endian processor, or ``1`` | ||
| on little endian processor. | ||
|
|
||
| Return value: The unpacked double. On error, this is ``-1.0`` and | ||
| :c:func:`PyErr_Occurred` is true (and an exception is set, most likely | ||
| :exc:`OverflowError`). | ||
|
|
||
| .. impl-detail:: | ||
| These functions always succeed in CPython. | ||
|
|
||
| .. c:function:: double PyFloat_Unpack2(const char *p, int le) | ||
|
|
||
| Unpack the IEEE 754 binary16 half-precision format as a C double. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.