minimum Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/minimum/ Sat, 28 Mar 2020 13:45:46 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 minimum Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/minimum/ 32 32 159787465 Min of two numbers in Go (Golang) https://vikasboss.github.io/min-of-two-numbers-golang/ https://vikasboss.github.io/min-of-two-numbers-golang/#respond Sat, 28 Mar 2020 13:41:22 +0000 https://vikasboss.github.io/?p=1877 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...

The post Min of two numbers in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
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

The post Min of two numbers in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/min-of-two-numbers-golang/feed/ 0 1877