math.go 645 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package math
  2. import (
  3. "f1-game/internal/types"
  4. "math"
  5. )
  6. func Max[E types.Ordered](val E, others ...E) E {
  7. maxVal := val
  8. for _, v := range others {
  9. if v > maxVal {
  10. maxVal = v
  11. }
  12. }
  13. return maxVal
  14. }
  15. func Min[E types.Ordered](val E, others ...E) E {
  16. minVal := val
  17. for _, v := range others {
  18. if v < minVal {
  19. minVal = v
  20. }
  21. }
  22. return minVal
  23. }
  24. func Round[E types.FloatType, T types.Number](val E) T {
  25. return T(math.Round(float64(val)))
  26. }
  27. func Ceil[E types.FloatType, T types.Number](val E) T {
  28. return T(math.Ceil(float64(val)))
  29. }
  30. func Floor[E types.FloatType, T types.Number](val E) T {
  31. return T(math.Floor(float64(val)))
  32. }