✨ 完成基础脚手架
This commit is contained in:
31
utils/math.go
Normal file
31
utils/math.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.ltd/lxh/logger"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type mathUtil struct{}
|
||||
|
||||
func MathUtil() *mathUtil {
|
||||
return &mathUtil{}
|
||||
}
|
||||
|
||||
func (m mathUtil) Sqrt(datas []float64, avg float64) float64 {
|
||||
if len(datas) == 0 {
|
||||
return 0
|
||||
}
|
||||
var aaa float64
|
||||
for _, d := range datas {
|
||||
co := d - avg
|
||||
aaa += co * co
|
||||
}
|
||||
d, err := strconv.ParseFloat(fmt.Sprintf("%.2f", math.Sqrt(aaa/float64(len(datas)))), 64)
|
||||
if err != nil {
|
||||
logger.Say.Errorf("生成标准差失败:%v", err)
|
||||
return 0
|
||||
}
|
||||
return d
|
||||
}
|
Reference in New Issue
Block a user