From 1858cb99ad2bb8328c479ef7489bf7db2515c5af Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sun, 8 Dec 2024 16:15:19 +0000 Subject: [PATCH 1/5] Update fmod() doc --- Doc/library/math.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index bf79b23a72bbf9..2db64ecf5e759c 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -248,16 +248,16 @@ Floating point arithmetic .. function:: fmod(x, y) - Return ``fmod(x, y)``, as defined by the platform C library. Note that the - Python expression ``x % y`` may not return the same result. The intent of the C - standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite - precision) equal to ``x - n*y`` for some integer *n* such that the result has - the same sign as *x* and magnitude less than ``abs(y)``. Python's ``x % y`` - returns a result with the sign of *y* instead, and may not be exactly computable - for float arguments. For example, ``fmod(-1e-100, 1e100)`` is ``-1e-100``, but - the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, which cannot be - represented exactly as a float, and rounds to the surprising ``1e100``. For - this reason, function :func:`fmod` is generally preferred when working with + Return the remainder of division ``x / y``, as defined by the platform C library + function ``fmod(x, y)``. Note that the Python expression ``x % y`` may not return + the same result. The intent of the C standard is that ``fmod(x, y)`` be exactly + (mathematically; to infinite precision) equal to ``x - n*y`` for some integer *n* + such that the result has the same sign as *x* and magnitude less than ``abs(y)``. + Python's ``x % y`` returns a result with the sign of *y* instead, and may not be + exactly computable for float arguments. For example, ``fmod(-1e-100, 1e100)`` + is ``-1e-100``, but the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, + which cannot be represented exactly as a float, and rounds to the surprising ``1e100``. + For this reason, the function :func:`fmod` is generally preferred when working with floats, while Python's ``x % y`` is preferred when working with integers. From f14e5391bb0c20af10009832a39489fb44e5b9d7 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:07:03 +0000 Subject: [PATCH 2/5] Update Doc/library/math.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/math.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index 2db64ecf5e759c..f9e080df48f0f4 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -248,7 +248,7 @@ Floating point arithmetic .. function:: fmod(x, y) - Return the remainder of division ``x / y``, as defined by the platform C library + Return the floating-point remainder of ``x / y``, as defined by the platform C library function ``fmod(x, y)``. Note that the Python expression ``x % y`` may not return the same result. The intent of the C standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite precision) equal to ``x - n*y`` for some integer *n* From ccaac54a9f4d5db5cae1e28a8788e84ccbea86a7 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:07:17 +0000 Subject: [PATCH 3/5] Update Doc/library/math.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/math.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index f9e080df48f0f4..7cb6f1762bbe2d 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -257,7 +257,7 @@ Floating point arithmetic exactly computable for float arguments. For example, ``fmod(-1e-100, 1e100)`` is ``-1e-100``, but the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, which cannot be represented exactly as a float, and rounds to the surprising ``1e100``. - For this reason, the function :func:`fmod` is generally preferred when working with + For this reason, :func:`fmod` is generally preferred when working with floats, while Python's ``x % y`` is preferred when working with integers. From e51ea67dd6e6a8c9ccd000df9d6a276fe4d00903 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:18:24 +0000 Subject: [PATCH 4/5] Remove formatting as per @skirpichev request This may be rejected by lint as the line is too long. --- Doc/library/math.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index 7cb6f1762bbe2d..fd89d41b82dd73 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -248,16 +248,16 @@ Floating point arithmetic .. function:: fmod(x, y) - Return the floating-point remainder of ``x / y``, as defined by the platform C library - function ``fmod(x, y)``. Note that the Python expression ``x % y`` may not return - the same result. The intent of the C standard is that ``fmod(x, y)`` be exactly - (mathematically; to infinite precision) equal to ``x - n*y`` for some integer *n* - such that the result has the same sign as *x* and magnitude less than ``abs(y)``. - Python's ``x % y`` returns a result with the sign of *y* instead, and may not be - exactly computable for float arguments. For example, ``fmod(-1e-100, 1e100)`` - is ``-1e-100``, but the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, - which cannot be represented exactly as a float, and rounds to the surprising ``1e100``. - For this reason, :func:`fmod` is generally preferred when working with + Return the floating-point remainder of ``x / y``, as defined by the platform C library function ``fmod(x, y)``. Note that the + Python expression ``x % y`` may not return the same result. The intent of the C + standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite + precision) equal to ``x - n*y`` for some integer *n* such that the result has + the same sign as *x* and magnitude less than ``abs(y)``. Python's ``x % y`` + returns a result with the sign of *y* instead, and may not be exactly computable + for float arguments. For example, ``fmod(-1e-100, 1e100)`` is ``-1e-100``, but + the result of Python's ``-1e-100 % 1e100`` is ``1e100-1e-100``, which cannot be + represented exactly as a float, and rounds to the surprising ``1e100``. For + this reason, function :func:`fmod` is generally preferred when working with floats, while Python's ``x % y`` is preferred when working with integers. From f729d6d43436ff22981d23b8209ff0afade6bc45 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Wed, 25 Dec 2024 09:36:29 +0000 Subject: [PATCH 5/5] Update Doc/library/math.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/math.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index fd89d41b82dd73..c78b313db5152d 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -248,7 +248,8 @@ Floating point arithmetic .. function:: fmod(x, y) - Return the floating-point remainder of ``x / y``, as defined by the platform C library function ``fmod(x, y)``. Note that the + Return the floating-point remainder of ``x / y``, + as defined by the platform C library function ``fmod(x, y)``. Note that the Python expression ``x % y`` may not return the same result. The intent of the C standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite precision) equal to ``x - n*y`` for some integer *n* such that the result has