Skip to content

Commit cffad22

Browse files
committed
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.
1 parent 96dee64 commit cffad22

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Doc/library/sys.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
694694
A :term:`named tuple` holding information about the float type. It
695695
contains low level information about the precision and internal
696696
representation. The values correspond to the various floating-point
697-
constants defined in the standard header file :file:`float.h` for the 'C'
698-
programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard
697+
constants defined by C implementation and in the standard header file :file:`float.h` for the 'C'
698+
programming language; see Annex F and section 5.2.4.2.2 of the 1999 ISO/IEC C standard
699699
[C99]_, 'Characteristics of floating types', for details.
700700

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

704704
* - attribute
705-
- float.h macro
705+
- C macro
706706
- explanation
707707

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

774+
* - .. attribute:: float_info.stdc_iec_559
775+
- :c:macro:`!__STDC_IEC_559__`
776+
- A boolean, indicating support the IEC 60559 floating-point
777+
standard (the Annex F of C99). If enabled, the
778+
:class:`float` type characteristics matches the IEC
779+
60559 double format and exceptional cases for
780+
the :mod:`math` functions follow to the section F.10
781+
of the C99 standard.
782+
774783
The attribute :attr:`sys.float_info.dig` needs further explanation. If
775784
``s`` is any string representing a decimal number with at most
776785
:attr:`!sys.float_info.dig` significant digits, then converting ``s`` to a
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a boolean flag, indicating support the IEC 60559 floating-point standard
2+
(the Annex F of C99). Patch by Sergey B Kirpichev.

Objects/floatobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ static PyStructSequence_Field floatinfo_fields[] = {
6868
{"radix", "FLT_RADIX -- radix of exponent"},
6969
{"rounds", "FLT_ROUNDS -- rounding mode used for arithmetic "
7070
"operations"},
71+
{"stdc_iec_559", "test if implementation supports the IEC 60559"
72+
" floating-point standard"},
7173
{0}
7274
};
7375

7476
static PyStructSequence_Desc floatinfo_desc = {
7577
"sys.float_info", /* name */
7678
floatinfo__doc__, /* doc */
7779
floatinfo_fields, /* fields */
78-
11
80+
12
7981
};
8082

8183
PyObject *
@@ -113,6 +115,7 @@ PyFloat_GetInfo(void)
113115
SetDblFlag(DBL_EPSILON);
114116
SetIntFlag(FLT_RADIX);
115117
SetIntFlag(FLT_ROUNDS);
118+
SetFlag(PyBool_FromLong(__STDC_IEC_559__));
116119
#undef SetIntFlag
117120
#undef SetDblFlag
118121
#undef SetFlag

0 commit comments

Comments
 (0)