Copysign()

chip01889226953 total contributions
Published Oct 3, 2023
Contribute to Docs
The Copysign()
of the math
package is an inbuilt function that returns a value based on the magnitude of the first argument and the sign of the second argument.
Syntax
import "math"
CpSgnXY = math.Copysign(x, y)
Where CpSgnXY
is the value, of type float64
, composed of the magnitude of x
and the sign of y
.
Example
The following code demonstrates the basic implementations of .Copysign()
:
package mainimport ("fmt""math")func main() {fmt.Println(math.Copysign(4.9, -1))}
The output will be:
-4.9
Codebyte Example
The following example shows how the Copysign()
function handles various arguments.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.