]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] Correct frexp() docs for zero and non-finite numbers (GH-149753) (GH-150654)
authorSergey B Kirpichev <skirpichev@gmail.com>
Sun, 31 May 2026 07:58:24 +0000 (10:58 +0300)
committerGitHub <noreply@github.com>
Sun, 31 May 2026 07:58:24 +0000 (07:58 +0000)
0.5 <= abs(m) < 1 is only true for finite nonzero numbers
(cherry picked from commit 5b5ffce05c211a5b0b74cd95eeb4c463614ee136)

Doc/library/math.rst
Modules/clinic/mathmodule.c.h
Modules/mathmodule.c

index 46d61388f7948274f2b10072183c4927737584c5..ebf0ea3901bb6dbe403bc7585b94d5f0c8db6cb6 100644 (file)
@@ -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
index 7af5fcccb2d14af840f1c994c899bfbd72b125e4..473efd8ef05a18a00b25eea05249fbc8d7884508 100644 (file)
@@ -76,8 +76,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__},
@@ -1009,4 +1010,4 @@ math_ulp(PyObject *module, PyObject *arg)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=ef101d15f144ab44 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9ed980dea18198be input=a9049054013a1b77]*/
index 66ad6d4c4de0c5adcc294987802e766de96757ed..e0a1db0fea8d88ef7bb0c49a4e1e3ac21198aa5e 100644 (file)
@@ -2095,13 +2095,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