| 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. |
| 4 | module math |
| 5 | |
| 6 | // min returns the minimum of `a` and `b` |
| 7 | @[inline] |
| 8 | pub 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] |
| 14 | pub 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] |
| 20 | pub fn abs[T](a T) T { |
| 21 | return if a < 0 { -a } else { a } |
| 22 | } |
| 23 | |