Skip to content

Conversation

skirpichev
Copy link
Owner

@skirpichev skirpichev commented Aug 9, 2025

This add hexadecimal floating point literals (IEEE 754-2008 §5.12.3) and support construction of floats from hexadecimal strings. Note that the syntax is more permissive: everything that is currently accepted by the float.fromhex(), but with a mandatory base specifier; it also allows grouping digits with underscores.

Examples:

>>> 0x1.1p-1
0.53125
>>> float('0x1.1')
1.0625
>>> 0x1.1
1.0625
>>> 0x1.1_1_1
1.066650390625

Minor changes:

  • Py_ISDIGIT/ISXDIGIT macros were transformed to functions

📚 Documentation preview 📚: https://cpython-previews--10.org.readthedocs.build/

@skirpichev
Copy link
Owner Author

python#114668

This add hexadecimal floating point literals (IEEE 754-2008 §5.12.3) and
support construction of floats from hexadecimal strings.  Note that the
syntax is more permissive: everything that is currently accepted by the
``float.fromhex()``, but with a mandatory base specifier; it also allows
grouping digits with underscores.

Examples:
```pycon
>>> 0x1.1p-1
0.53125
>>> float('0x1.1')
1.0625
>>> 0x1.1
1.0625
>>> 0x1.1_1_1
1.066650390625
```

Added compatibility code to not break access of existing int attributes.

E.g. 0x1.bit_length() will not require parentheses around the
hexadecimal integer literal (like 1.bit_length() for decimal int).

Minor changes: Py_ISDIGIT/ISXDIGIT macros were transformed to functions.
@skirpichev skirpichev force-pushed the hex-floatlit branch 2 times, most recently from 057bc45 to cd9bf16 Compare August 10, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant