From 2b56f6e6c6b837f6a57f1e8d56c193f836a652cb Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 9 Feb 2023 22:03:18 +0100 Subject: [PATCH] fix(Griewank): don't pass 0 in sqrt --- bench/cec2020/basicFunctions.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bench/cec2020/basicFunctions.go b/bench/cec2020/basicFunctions.go index 8fa5479..3880fe1 100644 --- a/bench/cec2020/basicFunctions.go +++ b/bench/cec2020/basicFunctions.go @@ -70,7 +70,8 @@ func Griewank(x []float64) float64 { for i := range x { sum += math.Pow(x[i], 2) / 4000 - prod -= math.Cos(x[i] / math.Sqrt(float64(i))) + // use i+1 in sqrt so that we don't get Nan. + prod *= math.Cos(x[i] / math.Sqrt(float64(i+1))) } return sum - prod + 1