The Wayback Machine - https://web.archive.org/web/20230107124436/https://www.geeksforgeeks.org/python-math-function-copysign/
Skip to content
Related Articles

Related Articles

Python math function | copysign()

Improve Article
Save Article
  • Last Updated : 01 Jan, 2019
Improve Article
Save Article

math.copysign() is a function exists in Standard math Library of Python. This function returns a float value consisting of magnitude from parameter x and the sign (+ve or -ve) from parameter y.

Syntax : math.copysign(x, y)

Parameters :
x : Integer value to be converted
y : Integer whose sign is required

Returns : float value consisting of magnitude from parameter x and the sign from parameter y.

Code #1:




# Python code to demonstrate copy.sign() function
import math
  
def func():
    a = 5
    b = -7
  
      
    # implementation of copysign
    c = math.copysign(a, b)
      
    return c
      
print (func())

Output :

-5.0

 
Code #2:




# Python code to demonstrate copy.sign() function
import math
  
def func():
    a = 10
    b = 10
  
      
    # implementation of copysign
    c = math.copysign(a, b)
      
    return c
      
print (func())

Output :

10

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!