clamp.go 339 B

1234567891011121314
  1. /*Package f64 provides helper functions for the float64 type.*/
  2. package f64
  3. // Clamp returns the value if it fits within the parameters min and max.
  4. // Otherwise returns the closest boundary parameter value.
  5. func Clamp(value, min, max float64) float64 {
  6. if value > max {
  7. return max
  8. }
  9. if value < min {
  10. return min
  11. }
  12. return value
  13. }