gitee.com/quant1x/num@v0.3.2/sqrt.go (about) 1 package num 2 3 import ( 4 "gitee.com/quant1x/num/math32" 5 "gitee.com/quant1x/num/x32" 6 "gitee.com/quant1x/num/x64" 7 "math" 8 ) 9 10 // Sqrt 求平方根 11 func Sqrt[T Number](v []T) []T { 12 var d any 13 var values any = v 14 switch fs := values.(type) { 15 case []float32: 16 d = x32.Sqrt(fs) 17 case []float64: 18 d = x64.Sqrt(fs) 19 default: 20 panic(ErrUnsupportedType) 21 } 22 23 return d.([]T) 24 } 25 26 func __go_sqrt_f64(x []float64) { 27 for i := 0; i < len(x); i++ { 28 x[i] = math.Sqrt(x[i]) 29 } 30 } 31 32 func __go_sqrt_f32(x []float32) { 33 for i := 0; i < len(x); i++ { 34 x[i] = math32.Sqrt(x[i]) 35 } 36 }