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