Skip to content

Provide access to the __STDC_IEC_559__ macro #138580

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. self-assigned this
    on Sep 6, 2025
  2. picnixz commented on Sep 6, 2025

    @picnixz
    Member

    I don't really think float_info is 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_info is 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 sys for features macros in general. Something like sys.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 math could be ok but functions affected by __STDC_IEC_559__ are not all in math.h and I feel weird to do if math.<whatever_flags>. math is rather home for mathematical constants and functions rather than the standards they follow. So, I think it's better that we keep in sys.

  3. emmatyping commented on Sep 6, 2025

    @emmatyping
    Member

    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 sysconfig however, since that is where platform configuration variables usually live?

  4. skirpichev commented on Sep 7, 2025

    @skirpichev
    MemberAuthor

    I don't really think float_info is a good place as __STDC_IEC_559__ also inidicates how various math functions behave

    Not 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

  5. skirpichev commented on Sep 10, 2025

    @skirpichev
    MemberAuthor
  6. vstinner commented on Sep 10, 2025

    @vstinner
    Member

    If the goal is to skip some tests, sysconfig is a good place for such variable.

  7. skirpichev commented on Sep 11, 2025

    @skirpichev
    MemberAuthor

    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.

  8. vstinner commented on Sep 11, 2025

    @vstinner
    Member

    The documentation should be updated in this case.

  9. added a commit that references this issue on Sep 12, 2025
  10. skirpichev commented on Sep 12, 2025

    @skirpichev
    MemberAuthor

    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.

  11. removed their assignment
    on Sep 12, 2025
  12. serhiy-storchaka commented on Sep 17, 2025

    @serhiy-storchaka
    Member

    What is the use of that flag in the user code?

  13. skirpichev commented on Sep 17, 2025

    @skirpichev
    MemberAuthor

    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.

  14. 15 remaining items

  15. added a commit that references this issue on Mar 24, 2026
  16. 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.

  17. self-assigned this
    on Mar 27, 2026
  18. 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.

  19. added a commit that references this issue on Mar 27, 2026
  20. removed their assignment
    on Mar 27, 2026
  21. added a commit that references this issue on Mar 27, 2026
  22. 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.

  23. added 2 commits that reference this issue on Apr 16, 2026
  24. 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