Standardizing error conditions
MODIFY
internal/cephes/cephes.go
internal/cephes/cephes.go
@@ -16,6 +16,8 @@ https://lists.debian.org/debian-legal/2004/12/msg00295.html
var (
badParamOutOfBounds = "cephes: parameter out of bounds"
+ badParamUnderflow = "cephes: underflow error"
+ badParamFunctionSingularity = "cephes: function singularity"
)
const (

MODIFY
internal/cephes/igam.go
internal/cephes/igam.go
@@ -146,7 +146,7 @@ func Igam(a, x float64) float64 {
}
if x < 0 || a <= 0 {
- panic("Igam: Domain error")
+ panic(badParamOutOfBounds)
}
// Asymptotic regime where a ~ x; see [2].
@@ -166,7 +166,7 @@ func Igam(a, x float64) float64 {
// IgamC computes the complemented incomplete Gamma integral
func IgamC(a, x float64) float64 {
if x < 0 || a <= 0 {
- panic("IgamC: Domain error")
+ panic(badParamOutOfBounds)
} else if x == 0 {
return 1
} else if x == math.MaxFloat64 || x == -math.SmallestNonzeroFloat64 {
@@ -208,7 +208,7 @@ func igamFac(a, x float64) float64 {
if math.Abs(a-x) > 0.4*math.Abs(a) {
ax := a*math.Log(x) - x - lgam(a)
if ax < -maxLog {
- panic("igamFac: Underflow error")
+ panic(badParamUnderflow)
}
return math.Exp(ax)
}

MODIFY
internal/cephes/igami.go
internal/cephes/igami.go
@@ -78,7 +78,7 @@ func IgamI(a, y0 float64) float64 {
dithresh := 5.0 * machEp
if y0 < 0 || y0 > 1 || a <= 0 {
- panic("IgamI: Domain error")
+ panic(badParamOutOfBounds)
}
if y0 == 0 {
@@ -195,7 +195,7 @@ func IgamI(a, y0 float64) float64 {
}
if x == 0 {
- panic("IgamI: Underflow error")
+ panic(badParamUnderflow)
}
return x

MODIFY
internal/cephes/zeta.go
internal/cephes/zeta.go
@@ -84,15 +84,15 @@ func Zeta(x, q float64) float64 {
}
if x < 1 {
- panic("Zeta: domain")
+ panic(badParamOutOfBounds)
}
if q <= 0 {
if q == math.Floor(q) {
- panic("Zeta: sing")
+ panic(badParamFunctionSingularity)
}
if x != math.Floor(x) {
- panic("Zeta: domain") // because q^-x not defined
+ panic(badParamOutOfBounds) // because q^-x not defined
}
}

Standardizing error conditions