Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ Constants

The :mod:`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. The current implementation will raise
the C99 standard, if :attr:`sys.float_info.stdc_iec_559` is true. The current implementation will raise
:exc:`ValueError` for invalid operations like ``sqrt(-1.0)`` or ``log(0.0)``
(where C99 Annex F recommends signaling invalid operation or divide-by-zero),
and :exc:`OverflowError` for results that overflow (for example,
Expand Down
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 true, 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
2 changes: 1 addition & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def test_attributes(self):
self.assertIsInstance(sys.exec_prefix, str)
self.assertIsInstance(sys.base_exec_prefix, str)
self.assertIsInstance(sys.executable, str)
self.assertEqual(len(sys.float_info), 11)
self.assertEqual(len(sys.float_info), 12)
self.assertEqual(sys.float_info.radix, 2)
self.assertEqual(len(sys.int_info), 4)
self.assertTrue(sys.int_info.bits_per_digit % 5 == 0)
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.
9 changes: 8 additions & 1 deletion Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ static PyStructSequence_Field floatinfo_fields[] = {
{"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,11 @@ PyFloat_GetInfo(void)
SetDblFlag(DBL_EPSILON);
SetIntFlag(FLT_RADIX);
SetIntFlag(FLT_ROUNDS);
#ifdef __STDC_IEC_559__
SetFlag(PyBool_FromLong(1));
#else
SetFlag(PyBool_FromLong(0));
#endif
#undef SetIntFlag
#undef SetDblFlag
#undef SetFlag
Expand Down
Loading