2022-01-05 19:02:20 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module math
|
|
|
|
|
|
|
|
// min returns the minimum of `a` and `b`
|
|
|
|
[inline]
|
2022-11-26 19:23:26 +03:00
|
|
|
pub fn min[T](a T, b T) T {
|
2022-01-05 19:02:20 +03:00
|
|
|
return if a < b { a } else { b }
|
|
|
|
}
|
|
|
|
|
|
|
|
// max returns the maximum of `a` and `b`
|
|
|
|
[inline]
|
2022-11-26 19:23:26 +03:00
|
|
|
pub fn max[T](a T, b T) T {
|
2022-01-05 19:02:20 +03:00
|
|
|
return if a > b { a } else { b }
|
|
|
|
}
|
|
|
|
|
|
|
|
// abs returns the absolute value of `a`
|
|
|
|
[inline]
|
2022-11-26 19:23:26 +03:00
|
|
|
pub fn abs[T](a T) T {
|
2022-04-27 13:23:37 +03:00
|
|
|
return if a < 0 { -a } else { a }
|
2022-01-05 19:02:20 +03:00
|
|
|
}
|