]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-138580: Add sys.float_info.iec_60559 boolean flag (#138811)
authorSergey B Kirpichev <skirpichev@gmail.com>
Tue, 24 Mar 2026 11:36:15 +0000 (14:36 +0300)
committerGitHub <noreply@github.com>
Tue, 24 Mar 2026 11:36:15 +0000 (11:36 +0000)
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.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/library/math.rst
Doc/library/sys.rst
Doc/whatsnew/3.15.rst
Lib/test/test_sys.py
Misc/NEWS.d/next/Library/2025-09-12-07-30-13.gh-issue-138580.Qr_fSH.rst [new file with mode: 0644]
Objects/floatobject.c

index 4a11aec15dfb737920cea5002d2b346b204ea59e..bb9983ed033814c3d2a655122154ec36eaf477f8 100644 (file)
@@ -848,7 +848,8 @@ 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.iec_60559` 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,
index b1461b0cbaf5284ba3199c1a1b9f8574a9e5018d..a034dce045cb8d6ba7f106607ab12e15671455bf 100644 (file)
@@ -694,15 +694,16 @@ 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
-   [C99]_, 'Characteristics of floating types', for details.
+   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
@@ -771,6 +772,12 @@ 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.iec_60559
+        - :c:macro:`!__STDC_IEC_559__`
+        - A boolean, indicating support the IEC 60559 floating-point standard.
+          If true, the :class:`float` type characteristics and behavior matches
+          the IEC 60559 double format.
+
    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
index ace02de7142e065206e10dcca6481b730e99ee7c..0973c387a1e5958fb3685600dbd5a3231b0b444e 100644 (file)
@@ -1015,6 +1015,11 @@ sys
 * Add :data:`sys.abi_info` namespace to improve access to ABI information.
   (Contributed by Klaus Zimmermann in :gh:`137476`.)
 
+* Add :data:`sys.float_info.iec_60559 <sys.float_info>`: a boolean flag,
+  indicating support the IEC 60559 floating-point standard (as specified by the
+  Annex F of C99).
+  (Contributed by Sergey B Kirpichev in :gh:`138580`.)
+
 
 tarfile
 -------
index a729efee18c3a1372360f9667f94f1af38c081e8..c912e8dd9e05bd2888e49b8708bdbaa9621ed848 100644 (file)
@@ -641,7 +641,7 @@ class SysModuleTest(unittest.TestCase):
         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)
diff --git a/Misc/NEWS.d/next/Library/2025-09-12-07-30-13.gh-issue-138580.Qr_fSH.rst b/Misc/NEWS.d/next/Library/2025-09-12-07-30-13.gh-issue-138580.Qr_fSH.rst
new file mode 100644 (file)
index 0000000..fd159db
--- /dev/null
@@ -0,0 +1,3 @@
+Add :data:`sys.float_info.iec_60559 <sys.float_info>`: a boolean flag,
+indicating support the IEC 60559 floating-point standard (as specified by the
+Annex F of C99).  Patch by Sergey B Kirpichev.
index 18871a4f3c51a95751cd1130a1935960c5c15c0c..b78fd3ccb47972319dce418b80a565f6885d7a37 100644 (file)
@@ -68,6 +68,8 @@ static PyStructSequence_Field floatinfo_fields[] = {
     {"radix",           "FLT_RADIX -- radix of exponent"},
     {"rounds",          "FLT_ROUNDS -- rounding mode used for arithmetic "
                     "operations"},
+    {"iec_60559",   "test if implementation supports the IEC 60559 "
+                    "floating-point standard"},
     {0}
 };
 
@@ -75,7 +77,7 @@ static PyStructSequence_Desc floatinfo_desc = {
     "sys.float_info",           /* name */
     floatinfo__doc__,           /* doc */
     floatinfo_fields,           /* fields */
-    11
+    12
 };
 
 PyObject *
@@ -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