Provide access to the __STDC_IEC_559__ macro #138580
Copy link
Copy link
Closed as not planned
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
This e.g. can allow us filter out some tests on systems, which don't conform to the C Annex F. Example: #138573.
I'm not sure where to put this stuff. In order of my preference:
- New boolean variable in the sys module?
- sys.float_info field? Though, sphinx docs says "The values correspond to the various floating-point constants defined in the standard header file float.h for the ‘C’ programming language".
- in the math module?
Edit:
- sysconfig variable as another place
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Activity
picnixz commentedon Sep 6, 2025
I don't really think
float_infois a good place as__STDC_IEC_559__also inidicates how various math functions behave so it's not just about floating-point values themselves (float_infois really about the representation of floats, not how the functions acting on it would behave).I believe we could also add a new namespace in
sysfor features macros in general. Something likesys.features_macros. However, that's only if we plan to add more macros there and apart from__STDC_IEC_60559_COMPLEX__and__STDC_IEC_60559_TYPES__, I don't think we have much to add there.Adding it to
mathcould be ok but functions affected by__STDC_IEC_559__are not all inmath.hand I feel weird to doif math.<whatever_flags>.mathis rather home for mathematical constants and functions rather than the standards they follow. So, I think it's better that we keep insys.emmatyping commentedon Sep 6, 2025
I agree noting the C headers that are relevant to match behavior would be nice to do. Would it make sense to put the values in
sysconfighowever, since that is where platform configuration variables usually live?skirpichev commentedon Sep 7, 2025
Not only. F.10 is just one of 10 sections.
For same reasons, math looks not very appropriate.
The problems is that IMO we don't have too much macros to expose. E.g.
__STDC_IEC_60559_COMPLEX__right now is in 99.9?% cases just a plain lie (or a compiler bug, whatever).Maybe. Though, this information is not used to configure CPython.
CC @FFY00 per experts index
skirpichev commentedon Sep 10, 2025
CC @vstinner
vstinner commentedon Sep 10, 2025
If the goal is to skip some tests, sysconfig is a good place for such variable.
skirpichev commentedon Sep 11, 2025
This is just an example.
Another one is documentation. Currently we have:
That's a lie, strictly speaking.
vstinner commentedon Sep 11, 2025
The documentation should be updated in this case.
pythongh-138580: add sys.float_info.stdc_iec_559 boolean flag
skirpichev commentedon Sep 12, 2025
PR #138811 is ready.
After some thinking I chose sys.float_info over new entry in the sys namespace. I think that will improve discoverability of this flag and it's logically belongs to float_info (i.e. indicates that the float type matches a particular IEC 60559 format).
If it's ok, I'll also update the math's documentation in this pr.
serhiy-storchaka commentedon Sep 17, 2025
What is the use of that flag in the user code?
skirpichev commentedon Sep 17, 2025
Basically, same as for our internal tests. To check that implementation conforms to some specification, else warn user, apply workarounds, etc.
IIUIC, we don't require from implementation even that floating-point format conforms to the IEEE 754 standard. Yet it's possible to check, c.f. floating-point arithmetic behavior.
15 remaining items
gh-138580: Add sys.float_info.iec_60559 boolean flag (#138811)
vstinner commentedon Mar 25, 2026
I merged #138811 which adds
sys.float_info.iec_60559flag. If someone disagrees, there is still time to revert the change before Python 3.15 final.skirpichev commentedon Mar 27, 2026
Yes, lets revert it.
It looks like on practice it doesn't indicate conformance to the standard. It can't be used to filter out tests or to give some promises in documentation.
pythongh-138580: revert PR 138811
gh-138580: Revert sys.float_info.iec_60559 boolean flag (#146501)
vstinner commentedon Mar 27, 2026
So it seems like
sys.float_info.iec_60559is only true (__STDC_IEC_559__macro is defined) on Linux platforms, using glibc or musl, on many architectures, on any Linux distribution, using GCC or Clang, but not on Android. It's false on all other platforms: Windows, macOS/iOS, WASI/Emscripten, FreeBSD, Solaris.See details: #138811 (comment)
@skirpichev chose to revert the flag since it's not widely adopted and so cannot be used in the Python suite.
pythongh-138580: Add sys.float_info.iec_60559 boolean flag (python#13…
pythongh-138580: Revert sys.float_info.iec_60559 boolean flag (python…
pythongh-138580: Add sys.float_info.iec_60559 boolean flag (python#13…
pythongh-138580: Revert sys.float_info.iec_60559 boolean flag (python…