Skip to content

Commit 0e91100

Browse files
fix: use tolerant comparison for BiquadCascade vs chained Biquad sections
Now that the QEMU test suites actually run (see previous commit), TestBiquadCascade.cascade_equals_serial_sections failed on real Cortex-M4/M7 hardware: EXPECT_FLOAT_EQ assumed bit-exact equality between BiquadCascade<float,2>::Filter's internal loop and two manually chained Biquad<float>::Filter calls computing the identical formula. Root cause: this hot path is compiled with #pragma GCC optimize("O3","fast-math"), which permits FMA contraction but does not guarantee the compiler fuses multiply-adds identically across differently-inlined call sites. On ARM VFP hardware (real FMA instructions) this produced a single 1-ULP divergence at iteration 3, which then compounded through the filter's feedback (z1/z2) state over the remaining iterations -- max absolute divergence ~9e-8, confirmed via raw bit-pattern instrumentation. x86 host never diverges since it doesn't contract without -mfma. This is expected, benign fast-math behavior, not an algorithm or infrastructure bug. Switch to EXPECT_NEAR with math::Tolerance<float>(), matching this file's existing convention for other cascade-vs-closed-form comparisons. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 0cfca5f commit 0e91100

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

numerical/filters/passive/test/TestBiquadCascade.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ TEST_F(TestBiquadCascade, cascade_equals_serial_sections)
233233
for (int i = 0; i < 20; ++i)
234234
{
235235
const float x{ static_cast<float>(i) * 0.1f };
236-
EXPECT_FLOAT_EQ(cascade.Filter(x), s1.Filter(s0.Filter(x)));
236+
EXPECT_NEAR(cascade.Filter(x), s1.Filter(s0.Filter(x)), math::Tolerance<float>());
237237
}
238238
}
239239

0 commit comments

Comments
 (0)