fix(signal): refuse filter designs whose coefficients overflow
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user