fix(signal): refuse filter designs whose coefficients overflow

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-28 21:36:09 +02:00
parent e9f268a461
commit 045ef28d24
5 changed files with 91 additions and 1 deletions
+13
View File
@@ -286,9 +286,22 @@ func design(sh shape, proto prototype, w1, w2 float64) (b, a []float64, err erro
// reference follows from the roots and is no business of the
// scaling.
scale := proto.gain / cmplx.Abs(hd)
// An extreme order leaves the float64 range here as it does in the
// Butterworth pair: an infinite or vanished scale, or a coefficient
// past the range, is a refusal rather than a filter of zeros or NaN.
if math.IsNaN(scale) || math.IsInf(scale, 0) || scale == 0 {
return nil, nil, base.Errf("%s: the order overflows the coefficient arithmetic; use a lower order", name)
}
for i := range b {
b[i] *= scale
}
for _, poly := range [2][]float64{b, a} {
for _, v := range poly {
if math.IsNaN(v) || math.IsInf(v, 0) {
return nil, nil, base.Errf("%s: the order overflows the coefficient arithmetic; use a lower order", name)
}
}
}
return b, a, nil
}