]> granicus.if.org Git - python/commitdiff
#12211: clarify math.copysign() documentation and docstring
authorAndrew Kuchling <amk@amk.ca>
Sun, 16 Feb 2014 16:11:25 +0000 (11:11 -0500)
committerAndrew Kuchling <amk@amk.ca>
Sun, 16 Feb 2014 16:11:25 +0000 (11:11 -0500)
Doc/library/math.rst
Modules/mathmodule.c

index 7c3ab596b9b2875d4e2e44ff471e48822407df01..0083409042362c77ff89e60160a73e694d38a8ca 100644 (file)
@@ -36,9 +36,12 @@ Number-theoretic and representation functions
 
 .. 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)
 
index 4b3e642ff60abecd6f58e71f0c5099544ad395f6..00e2612fd3b3a437463406b537de1a9e846c0fea 100644 (file)
@@ -906,7 +906,11 @@ PyDoc_STRVAR(math_ceil_doc,
              "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,