Go Copysign()
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.
Contribute to Docs
- 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.
Learn Go on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use Go (Golang), an open-source programming language supported by Google!
- Beginner Friendly.6 hours