https://github.com/python/cpython/commit/942ba2d87e1520647937a1f7b3971c4e5cd6dde1
commit: 942ba2d87e1520647937a1f7b3971c4e5cd6dde1
branch: 3.14
author: Sergey B Kirpichev <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-05-31T08:02:32Z
summary:

[3.14] Correct frexp() docs for zero and non-finite numbers (GH-149753) 
(GH-150653)

0.5 <= abs(m) < 1 is only true for finite nonzero numbers
(cherry picked from commit 5b5ffce05c211a5b0b74cd95eeb4c463614ee136)

files:
M Doc/library/math.rst
M Modules/clinic/mathmodule.c.h
M Modules/mathmodule.c

diff --git a/Doc/library/math.rst b/Doc/library/math.rst
index c14682f7fe51d98..241f043ede7a9fa 100644
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -321,10 +321,12 @@ Floating point manipulation functions
 
 .. function:: frexp(x)
 
-   Return the mantissa and exponent of *x* as the pair ``(m, e)``.  *m* is a 
float
-   and *e* is an integer such that ``x == m * 2**e`` exactly. If *x* is zero,
-   returns ``(0.0, 0)``, otherwise ``0.5 <= abs(m) < 1``.  This is used to 
"pick
-   apart" the internal representation of a float in a portable way.
+   Return the mantissa and exponent of *x* as the pair ``(m, e)``.
+   If *x* is a finite nonzero number, then *m* is a float with
+   ``0.5 <= abs(m) < 1.0`` and an integer *e* is such that
+   ``x == m * 2**e`` exactly.  Else, return ``(x, 0)``.
+   This is used to "pick apart" the internal representation of
+   a float in a portable way.
 
    Note that :func:`frexp` has a different call/return pattern
    than its C equivalents: it takes a single argument and return a pair of
diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h
index c2d0dc59e45de79..0abce3b6baaa2d1 100644
--- a/Modules/clinic/mathmodule.c.h
+++ b/Modules/clinic/mathmodule.c.h
@@ -130,8 +130,9 @@ PyDoc_STRVAR(math_frexp__doc__,
 "\n"
 "Return the mantissa and exponent of x, as pair (m, e).\n"
 "\n"
-"m is a float and e is an int, such that x = m * 2.**e.\n"
-"If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.");
+"If x is a finite nonzero number, then m is a float with\n"
+"0.5 <= abs(m) < 1.0 and an integer e is such that\n"
+"x == m * 2**e exactly.  Else, return (x, 0).");
 
 #define MATH_FREXP_METHODDEF    \
     {"frexp", (PyCFunction)math_frexp, METH_O, math_frexp__doc__},
@@ -1110,4 +1111,4 @@ math_ulp(PyObject *module, PyObject *arg)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=28730b795b51b528 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=18e16eef548c9c43 input=a9049054013a1b77]*/
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 4e66de891b5b31f..b28bfb4ce53efc8 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -2090,13 +2090,14 @@ math.frexp
 
 Return the mantissa and exponent of x, as pair (m, e).
 
-m is a float and e is an int, such that x = m * 2.**e.
-If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.
+If x is a finite nonzero number, then m is a float with
+0.5 <= abs(m) < 1.0 and an integer e is such that
+x == m * 2**e exactly.  Else, return (x, 0).
 [clinic start generated code]*/
 
 static PyObject *
 math_frexp_impl(PyObject *module, double x)
-/*[clinic end generated code: output=03e30d252a15ad4a input=96251c9e208bc6e9]*/
+/*[clinic end generated code: output=03e30d252a15ad4a input=215cf8ea28a0959b]*/
 {
     int i;
     /* deal with special cases directly, to sidestep platform

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to