Wednesday, July 3, 2024
HomeLanguagesPythonPython | math.copysign() function

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:




# Python code to demonstrate the working of copysign()
    
# importing "math" for mathematical operations 
import math 
    
a = 5.2
b = -25
    
# returning the copysign 
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:




# Python code to demonstrate the working of factorial()
  
# importing "math" for mathematical operations 
import math 
  
# returning the copysign
print (math.copysign(-13, 25.5))
print (math.copysign(2.87, -15))


Output:

13.0
-2.87
Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments