``````

In [1]:

import math

``````
``````

In [2]:

print(math.copysign(123, -100))

``````
``````

-123.0

``````
``````

In [3]:

print(math.copysign(123.0, -100.0))

``````
``````

-123.0

``````
``````

In [4]:

def my_sign_with_copysign(x):
return int(math.copysign(1, x))

``````
``````

In [5]:

print(my_sign_with_copysign(100))

``````
``````

1

``````
``````

In [6]:

print(my_sign_with_copysign(-100))

``````
``````

-1

``````
``````

In [7]:

print(type(my_sign_with_copysign(100)))

``````
``````

<class 'int'>

``````
``````

In [8]:

print(my_sign_with_copysign(1.23))

``````
``````

1

``````
``````

In [9]:

print(my_sign_with_copysign(-1.23))

``````
``````

-1

``````
``````

In [10]:

print(type(my_sign_with_copysign(1.23)))

``````
``````

<class 'int'>

``````
``````

In [11]:

print(my_sign_with_copysign(0))

``````
``````

1

``````
``````

In [12]:

print(my_sign_with_copysign(0.0))

``````
``````

1

``````
``````

In [13]:

print(my_sign_with_copysign(-0.0))

``````
``````

-1

``````
``````

In [14]:

print(my_sign_with_copysign(float('nan')))

``````
``````

1

``````
``````

In [15]:

print(my_sign_with_copysign(float('-nan')))

``````
``````

-1

``````
``````

In [16]:

# print(math.copysign(1, 3 + 4j))
# TypeError: can't convert complex to float

``````
``````

In [17]:

# print(my_sign_with_copysign(3 + 4j))
# TypeError: can't convert complex to float

``````