On this page
math.copysign
Prev: math.comb | Up: math | Next: math.cos
Rel: math.acos, math.acosh, math.asin, math.asinh
Ref: docs.python.org — math.copysign
Tags: #public #python3 #stdlib #math
Import
import math
from math import copysign
Signature & Overview
math.copysign(x, y, /)
Return a float with the magnitude (absolute value) of x but the sign of y.
Usage
import math
assert math.copysign(3.5, -1.0) == -3.5
assert math.copysign(-3.5, 0.0) == 3.5
Gotchas
- Preserves signed zero (
-0.0):math.copysign(1.0, -0.0)returns-1.0, making it the reliable way to inspect the sign of-0.0.
REPL Inspect
from math import copysign
help(copysign)
Linked from
Related notes
- tuts/python3/stdlib_module/math/comb Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/cos Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/math/acos Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/acosh Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asin Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asinh Linked here; shared tags: #math, #stdlib
- tuts/c/stdlib/math shared tags: #math, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #math, #stdlib
- tuts/c/stdlib/math/floor shared tags: #math, #stdlib