v / vlib / math / min_max_abs.v
22 lines · 19 sloc · 528 bytes · 763f94388b1ceff59c3e68ebda2c9f57197f32a4
Raw
1// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module math
5
6// min returns the minimum of `a` and `b`
7@[inline]
8pub fn min[T](a T, b T) T {
9 return if a < b { a } else { b }
10}
11
12// max returns the maximum of `a` and `b`
13@[inline]
14pub fn max[T](a T, b T) T {
15 return if a > b { a } else { b }
16}
17
18// abs returns the absolute value of `a`
19@[inline]
20pub fn abs[T](a T) T {
21 return if a < 0 { -a } else { a }
22}
23