Copying signs

Download python eBook

Example

In Python 2.6 and higher, math.copysign(x, y) returns x with the sign of y. The returned value is always a float.

Python 2.x2.6
math.copysign(-2, 3)    # 2.0
math.copysign(3, -3)    # -3.0
math.copysign(4, 14.2)  # 4.0
math.copysign(1, -0.0)  # -1.0, on a platform which supports signed zero

Stats

Contributors: 3
2016-07-30
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook