Python | math.copysign() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.copysign(a, b)
function return a float with the magnitude (absolute value) of a but the sign of b.
Syntax: math.copysign(a, b)
Parameter:
a, b: numeric values.
Returns: Return absolute value of a but the sign of b.
Code #1:
import math
a = 5.2
b = - 25
print ( "The copysign of 5.2 and -25 is : " , end = "")
print (math.copysign(a, b))
|
Output:
The copysign of 5.2 and -25 is : -5.2
Code #2:
import math
print (math.copysign( - 13 , 25.5 ))
print (math.copysign( 2.87 , - 15 ))
|
Last Updated :
11 Mar, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...