Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You are allowed to find the absolute value of the specified number with the help of Abs() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access the Abs() function.
- If you pass infinite(Inf) in this function, then this function will return +Inf
- If you pass NaN(not-a-number) in this function, then this function will return NaN.
func Abs(y float64) float64
Let us discuss this concept with the help of the given examples:
Result 1: 4.0 Result 2: 8.0 Result 3: +Inf
20.0 + 34.0 = 54.0