Skip to content

Instantly share code, notes, and snippets.

@sbinet
Last active August 16, 2018 10:44
Show Gist options
  • Save sbinet/549a233a4d662b759f68871110c4db51 to your computer and use it in GitHub Desktop.
Save sbinet/549a233a4d662b759f68871110c4db51 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"math"
"os"
"strconv"
)
func main() {
if len(os.Args) <= 1 {
fmt.Println("Not enough arguments")
os.Exit(1)
}
var (
min = +math.MaxFloat64
max = -math.MaxFloat64
)
for _, arg := range os.Args[1:] {
v, err := strconv.ParseFloat(arg, 64)
if err != nil {
log.Fatalf("could not convert %q to float64: %v", arg, err)
}
if v < min {
min = v
}
if v > max {
max = v
}
}
fmt.Printf("Min: %v\n", min)
fmt.Printf("Max: %v\n", max)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment