Added copysign(x, y) function to the math module
diff --git a/Doc/library/math.rst b/Doc/library/math.rst
index d0b03ed..36cdbce 100644
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -31,6 +31,14 @@
    should return an :class:`Integral` value.
 
 
+.. function:: copysign(x, y)
+
+   Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE
+   754 float, ``copysign(1, -0.0)`` returns *-1.0*.
+
+   ..versionadded:: 2.6
+
+
 .. function:: fabs(x)
 
    Return the absolute value of *x*.
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index d2da59b..f5bf1a3 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -229,6 +229,13 @@
         self.ftest('tanh(0)', math.tanh(0), 0)
         self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
 
+    def testCopysign(self):
+        self.assertEqual(math.copysign(1, 42), 1.0)
+        self.assertEqual(math.copysign(0., 42), 0.0)
+        self.assertEqual(math.copysign(1., -42), -1.0)
+        self.assertEqual(math.copysign(3, 0.), 3.0)
+        self.assertEqual(math.copysign(4., -0.), -4.0)
+
     def testIsnan(self):
         self.assert_(math.isnan(float("nan")))
         self.assert_(math.isnan(float("inf")* 0.))
diff --git a/Misc/NEWS b/Misc/NEWS
index ee0bec2..2a4b722 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,7 +12,8 @@
 Core and builtins
 -----------------
 
-- Issue #1640: Added math.isinf() and math.isnan() functions.
+- Issue #1640: Added math.isinf(x), math.isnan(x) and math.copysign(x, y)
+  functions.
 
 - Issue #1635: Platform independent creation and representation of NaN
   and INF. float("nan"), float("inf") and float("-inf") now work on every
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 7540b5d..2c6262d 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -133,6 +133,14 @@
       "cos(x)\n\nReturn the cosine of x (measured in radians).")
 FUNC1(cosh, cosh,
       "cosh(x)\n\nReturn the hyperbolic cosine of x.")
+#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+#ifdef MS_WINDOWS
+FUNC2(copysign, _copysign,
+#else
+FUNC2(copysign, copysign,
+#endif
+    "copysign(x,y)\n\nReturn x with the sign of y.");
+#endif
 FUNC1(exp, exp,
       "exp(x)\n\nReturn e raised to the power of x.")
 FUNC1(fabs, fabs,
@@ -375,6 +383,9 @@
 	{"atan",	math_atan,	METH_O,		math_atan_doc},
 	{"atan2",	math_atan2,	METH_VARARGS,	math_atan2_doc},
 	{"ceil",	math_ceil,	METH_O,		math_ceil_doc},
+#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+	{"copysign",	math_copysign,	METH_VARARGS,	math_copysign_doc},
+#endif
 	{"cos",		math_cos,	METH_O,		math_cos_doc},
 	{"cosh",	math_cosh,	METH_O,		math_cosh_doc},
 	{"degrees",	math_degrees,	METH_O,		math_degrees_doc},