Overview
math package of GO provides a Max method that can be used to get the maximum of two numbers.
Below is the signature of the function. It takes input two float numbers and returns a float.
func Max(x, y float64) float64
Also some special cases of Max function are
- Max(x, +Inf) = Max(+Inf, x) = +Inf
- Max(x, NaN) = Max(NaN, x) = NaN
- Max(+0, ±0) = Max(±0, +0) = +0
- Max(-0, -0) = -0
Code:
package main
import (
"fmt"
"math"
)
func main() {
max := math.Max(2, 3)
fmt.Println(max)
max = math.Max(-2.1, -3.3)
fmt.Println(max)
}
Output:
3
-2.1