Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

GoLang – Copysign() Function – Examples & Explanation

Copysign() function is used to show the magnitude of x and the sign of y where x and y are the given inputs (parameters).
The standard math package of Go programming language has Copysign() function. The purpose of this function is to get the return value (Output) with the magnitude of x and sign of y (where x and y are the arguments).

Syntax of Copysign() Function in Go Language

The syntax of Copysign() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.

 

Parameters of Copysign() Function in Go Language

x – Where x is and y are any Valid float64 Input values. This parameter is required.

 

Error Handling

If the x or y parameters are not numbers (numeric values) Copysign() function will return an error .
If there are no arguments (x or y – input values) passes to the function, then the compiler will produce an error.

 

Return Value of Copysign() Function in Go Language

Copysign() function will return the magnitude of x parameter and the sign of y parameter.

 

GoLang Copysign() Function Example 1


Output:
20

 

GoLang Copysign() Function Example 2


Output:
-0

 

GoLang Copysign() Function Example 3


Output:
-17.6

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved