You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide access to the __STDC_IEC_559__ macro #138580
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
And what is the user supposed to do if that flag is false?
Give up, for example.
New flag is just a quick way to say if everything is ok (e.g. arithmetic ops not suffer from double rounding).
If we add a flag for IEC 559, we also need to add a flag for IEEE 754.
I don't think it does make sense. For C standard, the IEC 559 means "latest revision of IEC 60559:1989 (IEEE 754–1985)". But there is only one major upgrade: IEC 60559:2011 (IEEE 754-2008). So, we could introduce ieee_754 flag to denote that implementation conforms to ancient IEEE 754–1985. Hardly it's useful.
__STDC_IEC_559__ is deprecated in C23. What do we supposed to do in future?
Roughly speaking, it's just renamed to __STDC_IEC_60559_BFP__. When C23 will be a minimal build requirement - we could check that define instead.
Python can be implemented not only in C. Other implementation can, theoretically, have non-standard floats.
stdc_iec_559 differs from other sys.float_info fields -- it is not defined in float.h.
New flag is just a quick way to say if everything is ok (e.g. arithmetic ops not suffer from double rounding).
This looks similar to X87_DOUBLE_ROUNDING provided by sysconfig. Isn't a better place for __STDC_IEC_559__? Things like SIZEOF_DOUBLE and HAVE_LONG_DOUBLE are also only available in sysconfig.
This looks similar to X87_DOUBLE_ROUNDING provided by sysconfig.
Well, every setting in sys.float_info can be turned into sysconfig variable. What's the rule here? When flag should be here and when in the sys namespace?
@skirpichev corrected me -- __STDC_IEC_559__ was just renamed to __STDC_IEC_60559_BFP__ with keepeng an old name as a deprecated alias. There is no problem here.
I am not sure whether it is worth to add this flag to sys.float_info because it is so different from other fields. If we are going to add more fields, this may be a way. Other option -- add it to sys.abi_info, but this can clutter it very fast.
There are many underscored names in sys -- this is yet one option.
If the macro is deprecated and mostly used in tests, I agree that sysconfig is a good home to expose it in Python.
It's not deprecated as a feature, just renamed.
And I strongly suspect it could be helpful not just for tests in the future. See PR, it includes changes in docs.
__STDC_IEC_559__ was just renamed to __STDC_IEC_60559_BFP__ with keepeng an old name as a deprecated alias.
Yes.
I am not sure whether it is worth to add this flag to sys.float_info because it is so different from other fields.
It's different (boolean flag instead of int/float's). Though, it's value is related to other fields (i.e. identify if they have some selected configuration, or not).
Other option -- add it to sys.abi_info, but this can clutter it very fast.
Still, if float_info is not an option - perhaps this is better than root of the sys namespace, for discoverability.
There are many underscored names in sys -- this is yet one option.
If you are about double-underscored names, they have very specific meaning (backup for overridden values). But with name like sys.stdc_iec_559 - it's not an issue.
Between sys.stdc_iec_559 and sys.float_info.stdc_iec_559, I prefer strongly sys.float_info.stdc_iec_559. The sys module already has too many attributes.
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.
So it seems like sys.float_info.iec_60559 is 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.
Activity
serhiy-storchaka commentedon Sep 17, 2025
So this is only to skip some tests?
What flag is used to denote that floating-point format conforms to the IEEE 754 standard?
skirpichev commentedon Sep 17, 2025
No. It's to check how a/b is rounded, for example.
None. But you could compare sys.float_info attributes with IEEE double format to detect that.
serhiy-storchaka commentedon Sep 17, 2025
And what is the user supposed to do if that flag is false?
Could you test how a/b is rounded to detect the IEC 559 support?
If we add a flag for IEC 559, we also need to add a flag for IEEE 754. And they have to be in one place, wherever that may be.
BTW,
__STDC_IEC_559__is deprecated in C23. What do we supposed to do in future? Always set that flag to False?skirpichev commentedon Sep 18, 2025
Give up, for example.
New flag is just a quick way to say if everything is ok (e.g. arithmetic ops not suffer from double rounding).
I don't think it does make sense. For C standard, the IEC 559 means "latest revision of IEC 60559:1989 (IEEE 754–1985)". But there is only one major upgrade: IEC 60559:2011 (IEEE 754-2008). So, we could introduce ieee_754 flag to denote that implementation conforms to ancient IEEE 754–1985. Hardly it's useful.
Roughly speaking, it's just renamed to
__STDC_IEC_60559_BFP__. When C23 will be a minimal build requirement - we could check that define instead.serhiy-storchaka commentedon Sep 18, 2025
Python can be implemented not only in C. Other implementation can, theoretically, have non-standard floats.
stdc_iec_559 differs from other sys.float_info fields -- it is not defined in
float.h.This looks similar to
X87_DOUBLE_ROUNDINGprovided bysysconfig. Isn't a better place for__STDC_IEC_559__? Things like SIZEOF_DOUBLE and HAVE_LONG_DOUBLE are also only available insysconfig.skirpichev commentedon Sep 19, 2025
See #138580 (comment)
Well, every setting in sys.float_info can be turned into sysconfig variable. What's the rule here? When flag should be here and when in the sys namespace?
vstinner commentedon Sep 22, 2025
If the macro is deprecated and mostly used in tests, I agree that
sysconfigis a good home to expose it in Python.serhiy-storchaka commentedon Sep 22, 2025
@skirpichev corrected me --
__STDC_IEC_559__was just renamed to__STDC_IEC_60559_BFP__with keepeng an old name as a deprecated alias. There is no problem here.I am not sure whether it is worth to add this flag to
sys.float_infobecause it is so different from other fields. If we are going to add more fields, this may be a way. Other option -- add it tosys.abi_info, but this can clutter it very fast.There are many underscored names in
sys-- this is yet one option.skirpichev commentedon Oct 1, 2025
It's not deprecated as a feature, just renamed.
And I strongly suspect it could be helpful not just for tests in the future. See PR, it includes changes in docs.
Yes.
It's different (boolean flag instead of int/float's). Though, it's value is related to other fields (i.e. identify if they have some selected configuration, or not).
Still, if float_info is not an option - perhaps this is better than root of the sys namespace, for discoverability.
If you are about double-underscored names, they have very specific meaning (backup for overridden values). But with name like
sys.stdc_iec_559- it's not an issue.vstinner commentedon Oct 1, 2025
Between
sys.stdc_iec_559andsys.float_info.stdc_iec_559, I prefer stronglysys.float_info.stdc_iec_559. Thesysmodule already has too many attributes.skirpichev commentedon Oct 29, 2025
Will be ok to mention something like
sysconfig.get_config_var('__STDC_IEC_559__')in docs? This looks too verbose for me.skirpichev commentedon Oct 29, 2025
CC @tim-one
skirpichev commentedon Mar 13, 2026
Another possible use case is replacement of the
float.__getformat__()method, as discussed here: #145633 (comment).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…