Skip to content

Provide access to the __STDC_IEC_559__ macro #138580

Closed as not planned
Closed as not planned

Description

@skirpichev

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:

  1. New boolean variable in the sys module?
  2. 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".
  3. 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

Activity

  1. serhiy-storchaka commented on Sep 17, 2025

    @serhiy-storchaka
    Member

    So this is only to skip some tests?

    What flag is used to denote that floating-point format conforms to the IEEE 754 standard?

  2. skirpichev commented on Sep 17, 2025

    @skirpichev
    MemberAuthor

    So this is only to skip some tests?

    No. It's to check how a/b is rounded, for example.

    What flag is used to denote that floating-point format conforms to the IEEE 754 standard?

    None. But you could compare sys.float_info attributes with IEEE double format to detect that.

  3. serhiy-storchaka commented on Sep 17, 2025

    @serhiy-storchaka
    Member

    It's to check how a/b is rounded, for example.

    And what is the user supposed to do if that flag is false?

    But you could compare sys.float_info attributes with IEEE double format to detect that.

    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?

  4. skirpichev commented on Sep 18, 2025

    @skirpichev
    MemberAuthor

    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.

  5. serhiy-storchaka commented on Sep 18, 2025

    @serhiy-storchaka
    Member

    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.

  6. skirpichev commented on Sep 19, 2025

    @skirpichev
    MemberAuthor

    stdc_iec_559 differs from other sys.float_info fields -- it is not defined in float.h.

    See #138580 (comment)

    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?

  7. vstinner commented on Sep 22, 2025

    @vstinner
    Member

    If the macro is deprecated and mostly used in tests, I agree that sysconfig is a good home to expose it in Python.

  8. serhiy-storchaka commented on Sep 22, 2025

    @serhiy-storchaka
    Member

    @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.

  9. self-assigned this
    on Oct 1, 2025
  10. skirpichev commented on Oct 1, 2025

    @skirpichev
    MemberAuthor

    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.

  11. vstinner commented on Oct 1, 2025

    @vstinner
    Member

    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.

  12. skirpichev commented on Oct 29, 2025

    @skirpichev
    MemberAuthor

    Will be ok to mention something like sysconfig.get_config_var('__STDC_IEC_559__') in docs? This looks too verbose for me.

  13. skirpichev commented on Oct 29, 2025

    @skirpichev
    MemberAuthor
  14. removed their assignment
    on Oct 31, 2025
  15. skirpichev commented on Mar 13, 2026

    @skirpichev
    MemberAuthor

    Another possible use case is replacement of the float.__getformat__() method, as discussed here: #145633 (comment).

  16. added a commit that references this issue on Mar 24, 2026
  17. vstinner commented on Mar 25, 2026

    @vstinner
    Member

    I merged #138811 which adds sys.float_info.iec_60559 flag. If someone disagrees, there is still time to revert the change before Python 3.15 final.

  18. self-assigned this
    on Mar 27, 2026
  19. skirpichev commented on Mar 27, 2026

    @skirpichev
    MemberAuthor

    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.

  20. added a commit that references this issue on Mar 27, 2026
  21. removed their assignment
    on Mar 27, 2026
  22. added a commit that references this issue on Mar 27, 2026
  23. vstinner commented on Mar 27, 2026

    @vstinner
    Member

    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.

    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.

  24. added 2 commits that reference this issue on Apr 16, 2026
  25. added 2 commits that reference this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions