Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-138580: add sys.float_info.stdc_iec_559 boolean flag
This value indicating support the IEC 60559 floating-point standard (the
Annex F of C99).  If enabled, the float type characteristics matches the
IEC 60559 double format and exceptional cases for the math's functions
follow to the section F.10 of the C99 standard.
  • Loading branch information
skirpichev committed Sep 12, 2025
commit cffad22e809ace980f164ad410c20734872f9bce
15 changes: 12 additions & 3 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
A :term:`named tuple` holding information about the float type. It
contains low level information about the precision and internal
representation. The values correspond to the various floating-point
constants defined in the standard header file :file:`float.h` for the 'C'
programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard
constants defined by C implementation and in the standard header file :file:`float.h` for the 'C'
programming language; see Annex F and section 5.2.4.2.2 of the 1999 ISO/IEC C standard
[C99]_, 'Characteristics of floating types', for details.

.. list-table:: Attributes of the :data:`!float_info` :term:`named tuple`
:header-rows: 1

* - attribute
- float.h macro
- C macro
- explanation

* - .. attribute:: float_info.epsilon
Expand Down Expand Up @@ -771,6 +771,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
All other values for :c:macro:`!FLT_ROUNDS` characterize
implementation-defined rounding behavior.

* - .. attribute:: float_info.stdc_iec_559
- :c:macro:`!__STDC_IEC_559__`
- A boolean, indicating support the IEC 60559 floating-point
standard (the Annex F of C99). If enabled, the
:class:`float` type characteristics matches the IEC
60559 double format and exceptional cases for
the :mod:`math` functions follow to the section F.10
of the C99 standard.

The attribute :attr:`sys.float_info.dig` needs further explanation. If
``s`` is any string representing a decimal number with at most
:attr:`!sys.float_info.dig` significant digits, then converting ``s`` to a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a boolean flag, indicating support the IEC 60559 floating-point standard
(the Annex F of C99). Patch by Sergey B Kirpichev.
5 changes: 4 additions & 1 deletion Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@
{"radix", "FLT_RADIX -- radix of exponent"},
{"rounds", "FLT_ROUNDS -- rounding mode used for arithmetic "
"operations"},
{"stdc_iec_559", "test if implementation supports the IEC 60559"
" floating-point standard"},
{0}
};

static PyStructSequence_Desc floatinfo_desc = {
"sys.float_info", /* name */
floatinfo__doc__, /* doc */
floatinfo_fields, /* fields */
11
12
};

PyObject *
Expand Down Expand Up @@ -113,6 +115,7 @@
SetDblFlag(DBL_EPSILON);
SetIntFlag(FLT_RADIX);
SetIntFlag(FLT_ROUNDS);
SetFlag(PyBool_FromLong(__STDC_IEC_559__));

Check failure on line 118 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'__STDC_IEC_559__': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 118 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'__STDC_IEC_559__': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 118 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'__STDC_IEC_559__': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 118 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'__STDC_IEC_559__': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
#undef SetIntFlag
#undef SetDblFlag
#undef SetFlag
Expand Down
Loading