[Python-checkins] cpython (3.3): #12211: clarify math.copysign() documentation and docstring

andrew.kuchling python-checkins at python.org
Sun Feb 16 17:14:17 CET 2014


http://hg.python.org/cpython/rev/3ad7725b5013
changeset:   89213:3ad7725b5013
branch:      3.3
parent:      89210:383f4eede628
user:        Andrew Kuchling <amk at amk.ca>
date:        Sun Feb 16 11:11:25 2014 -0500
summary:
  #12211: clarify math.copysign() documentation and docstring

files:
  Doc/library/math.rst |  7 +++++--
  Modules/mathmodule.c |  6 +++++-
  2 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Doc/library/math.rst b/Doc/library/math.rst
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -36,9 +36,12 @@
 
 .. function:: copysign(x, y)
 
-   Return *x* with the sign of *y*.  On a platform that supports
-   signed zeros, ``copysign(1.0, -0.0)`` returns *-1.0*.
+   Return a float with the magnitude (absolute value) of *x* but the sign of
+   *y*.  On platforms that support signed zeros, ``copysign(1.0, -0.0)``
+   returns *-1.0*.
 
+   If *x* is NaN, *y* is ignored and NaN is returned.  If *y* is NaN,
+   it is treated as positive: ``copysign(-1.0, NaN)`` returns 1.0.
 
 .. function:: fabs(x)
 
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -906,7 +906,11 @@
              "This is the smallest integral value >= x.");
 
 FUNC2(copysign, copysign,
-      "copysign(x, y)\n\nReturn x with the sign of y.")
+      "copysign(x, y)\n\nReturn a float with the magnitude (absolute value) "
+      "of x but the sign \nof y. On platforms that support signed zeros, "
+      "copysign(1.0, -0.0) \nreturns -1.0.\n\n"
+      "If x is NaN, y is ignored and NaN is returned. If y is NaN, it is\n"
+      "treated as positive.")
 FUNC1(cos, cos, 0,
       "cos(x)\n\nReturn the cosine of x (measured in radians).")
 FUNC1(cosh, cosh, 1,

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list