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

See also:

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
@skirpichev skirpichev marked this pull request as ready for review October 10, 2025 05:51
@skirpichev skirpichev closed this Oct 10, 2025
@skirpichev skirpichev deleted the hex-floatlit branch October 10, 2025 11: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.

2 participants