math.go 712 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package internal
  2. // The ugly side of Go.
  3. // template <typename T> please!
  4. // Min calculates the minimum of two 32-bit integers.
  5. func Min(a int, b int) int {
  6. if a < b {
  7. return a
  8. }
  9. return b
  10. }
  11. // Min64 calculates the minimum of two 64-bit integers.
  12. func Min64(a int64, b int64) int64 {
  13. if a < b {
  14. return a
  15. }
  16. return b
  17. }
  18. // Max calculates the maximum of two 32-bit integers.
  19. func Max(a int, b int) int {
  20. if a < b {
  21. return b
  22. }
  23. return a
  24. }
  25. // Max64 calculates the maximum of two 64-bit integers.
  26. func Max64(a int64, b int64) int64 {
  27. if a < b {
  28. return b
  29. }
  30. return a
  31. }
  32. // Abs64 calculates the absolute value of a 64-bit integer.
  33. func Abs64(v int64) int64 {
  34. if v <= 0 {
  35. return -v
  36. }
  37. return v
  38. }