Repository navigation
Provide access to the __STDC_IEC_559__ macro #138580
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on 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.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?I don't really think float_info is a good place as
__STDC_IEC_559__also inidicates how various math functions behaveNot only. F.10 is just one of 10 sections.
Adding it to math could be ok
For same reasons, math looks not very appropriate.
I believe we could also add a new namespace in sys for features macros in general. Something like sys.features_macros.
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).Would it make sense to put the values in sysconfig however, since that is where platform configuration variables usually live?
Maybe. Though, this information is not used to configure CPython.
CC @FFY00 per experts index
CC @vstinner
If the goal is to skip some tests, sysconfig is a good place for such variable.
If the goal is to skip some tests
This is just an example.
Another one is documentation. Currently we have:
The math module consists mostly of thin wrappers around the platform C math library functions. Behavior in exceptional cases follows Annex F of the C99 standard where appropriate.
That's a lie, strictly speaking.
The documentation should be updated in this case.
- added a commit that references this issue
on 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.
What is the use of that flag in the user code?
What is the use of that flag in the user code?
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
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.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.
- added a commit that references this issue
on 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.
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:
Edit:
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