chore(go): move functions to its own file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-06-16 17:15:39 +02:00
parent 826347f7a7
commit 3d00f09914
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 39 additions and 35 deletions

View File

@ -3,8 +3,6 @@
package bench
import "math"
type funcParams struct {
min float64
max float64
@ -34,36 +32,3 @@ func (*funcParams) Min(self *funcParams) float64 {
func (*funcParams) Max(self *funcParams) float64 {
return self.max
}
// Schwefel computes a value of the Schwefel function for x.
func Schwefel(x []float64) float64 {
var res float64
for _, val := range x {
res += val * math.Sin(math.Sqrt(math.Abs(val)))
}
return 418.9829*float64(len(x)) - res
}
// DeJong1st computes the value of the 1st De Jong function for x.
func DeJong1st(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Floor(val)
}
return res
}
// DeJong2nd computes the value of the 2nd De Jong function for x.
func DeJong2nd(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Pow(val, 2)
}
return res
}

39
bench/functions.go Normal file
View File

@ -0,0 +1,39 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package bench
import "math"
// Schwefel computes a value of the Schwefel function for x.
func Schwefel(x []float64) float64 {
var res float64
for _, val := range x {
res += val * math.Sin(math.Sqrt(math.Abs(val)))
}
return 418.9829*float64(len(x)) - res
}
// DeJong1st computes the value of the 1st De Jong function for x.
func DeJong1st(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Floor(val)
}
return res
}
// DeJong2nd computes the value of the 2nd De Jong function for x.
func DeJong2nd(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Pow(val, 2)
}
return res
}