Addressing feedback on arrays and variable declaration
MODIFY
internal/cephes/unity.go
internal/cephes/unity.go
@@ -28,7 +28,7 @@ const (
// for
// \frac{1}{\sqrt{2}} <= x < \sqrt{2}
// Theoretical peak relative error = 2.32e-20
-var lP = []float64{
+var lP = [...]float64{
4.5270000862445199635215E-5,
4.9854102823193375972212E-1,
6.5787325942061044846969E0,
@@ -38,7 +38,7 @@ var lP = []float64{
2.0039553499201281259648E1,
}
-var lQ = []float64{
+var lQ = [...]float64{
1.5062909083469192043167E1,
8.3047565967967209469434E1,
2.2176239823732856465394E2,
@@ -55,7 +55,7 @@ func log1p(x float64) float64 {
return math.Log(z)
}
z = x * x
- z = -0.5*z + x*(z*polevl(x, lP, 6)/p1evl(x, lQ, 6))
+ z = -0.5*z + x*(z*polevl(x, lP[:], 6)/p1evl(x, lQ[:], 6))
return x + z
}

MODIFY
internal/cephes/zeta.go
internal/cephes/zeta.go
@@ -17,7 +17,7 @@ import "math"
// where
// B_{2k}
// are Bernoulli numbers.
-var zetaCoefs = []float64{
+var zetaCoefs = [...]float64{
12.0,
-720.0,
30240.0,
@@ -92,10 +92,10 @@ func Zeta(x, q float64) float64 {
s -= 0.5 * b
a = 1.0
k := 0.0
- for i = 0; i < 12; i++ {
+ for _, coef := range zetaCoefs {
a *= x + k
b /= w
- t := a * b / zetaCoefs[i]
+ t := a * b / coef
s = s + t
t = math.Abs(t / s)
if t < machEp {

MODIFY
internal/misc/fsolve.go
internal/misc/fsolve.go
@@ -67,10 +67,11 @@ func falsePosition(x1, x2, f1, f2, absErr, relErr, bisectTil float64, f objectiv
}
gamma := 1.0
- nFalseP := 0
+
w := math.Abs(x2 - x1)
lastBisectWidth := w
+ var nFalseP int
var x3, f3, bestX, bestF float64
for i := 0; i < maxIterations; i++ {
switch state {

Addressing feedback on arrays and variable declaration