utility.go 443 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. */
  6. package netaddr
  7. func min(a, b int) int {
  8. if a < b {
  9. return a
  10. }
  11. return b
  12. }
  13. func max(a, b int) int {
  14. if a < b {
  15. return b
  16. }
  17. return a
  18. }
  19. func clamp(x, a, b int) int {
  20. if a > b {
  21. a, b = b, a
  22. }
  23. return min(max(x, a), b)
  24. }