File: xmath_go1.21.go

package info (click to toggle)
golang-github-bradenaw-juniper 0.15.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 872 kB
  • sloc: sh: 27; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//go:build go1.21

package xmath

import "cmp"

// Min returns the minimum of a and b based on the < operator.
//
// Deprecated: min is a builtin as of Go 1.21.
func Min[T cmp.Ordered](a, b T) T {
	return min(a, b)
}

// Max returns the maximum of a and b based on the > operator.
//
// Deprecated: max is a builtin as of Go 1.21.
func Max[T cmp.Ordered](a, b T) T {
	return max(a, b)
}

// Clamp clamps the value of x to within min and max.
func Clamp[T cmp.Ordered](x, min, max T) T {
	if x < min {
		return min
	}
	if x > max {
		return max
	}
	return x
}