From 5ff6f421d4398f2bf2f78654a2eddd39d9da5b3d Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Sun, 26 Feb 2017 01:03:47 -0800 Subject: [PATCH] max --- math_util.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/math_util.go b/math_util.go index 8c3f5da..4fc1a84 100644 --- a/math_util.go +++ b/math_util.go @@ -26,6 +26,20 @@ var ( type mathUtil struct{} +// Max returns the maximum value of a group of floats. +func (m mathUtil) Max(values ...float64) float64 { + if len(values) == 0 { + return 0 + } + max := values[0] + for _, v := range values { + if max < v { + max = v + } + } + return max +} + // MinAndMax returns both the min and max in one pass. func (m mathUtil) MinAndMax(values ...float64) (min float64, max float64) { if len(values) == 0 {