Skip to content

Conversation

@roderickvd
Copy link
Member

@roderickvd roderickvd commented Sep 6, 2025

The CI got broken when the no_std implementations for f32 and f64 were custom-rolled instead of using core intrinsics in this commit: cd8d893. Beyond breaking the CI, RMS values are way off.

Problem

The current implementation:

  • takes an initial guess without refinement
  • uses an incorrect bias for f64
  • causing wildly inaccurate values:
failures:

---- dasp_rms/src/lib.rs - Rms<F,S>::next (line 113) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' (6233708) panicked at dasp_rms/src/lib.rs:10:5:
assertion `left == right` failed
  left: [5.593755989478844e-155]
 right: [0.5]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- dasp_rms/src/lib.rs - Rms<F,S>::current (line 172) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' (6233709) panicked at dasp_rms/src/lib.rs:10:5:
assertion `left == right` failed
  left: [2.631772124e-315]
 right: [0.0]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- dasp_rms/src/lib.rs - Rms<F,S>::reset (line 62) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' (6233711) panicked at dasp_rms/src/lib.rs:13:5:
assertion `left == right` failed
  left: [2.631772124e-315]
 right: [0.0]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- dasp_signal/src/rms.rs - rms::SignalRms::rms (line 26) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' (6236011) panicked at dasp_signal/src/rms.rs:13:5:
assertion `left == right` failed
  left: [[6.749798802814877e-155], [9.136468277877633e-155], [7.458341613357585e-155]]
 right: [[0.6363961030678927], [0.8514693182963201], [0.7071067811865476]]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Solution

This PR improves the initial guess and uses Newton-Raphson refinement to improve the accuracy to >6 decimal places.

Handles special cases (NaN, zero, negative, infinity) and uses
Newton-Raphson refinement for better accuracy.

- Updated RMS doc tests to account for >6 decimal precision.
- Inlined std sqrt functions for f32 and f64 for performance.
@roderickvd roderickvd force-pushed the fix/no-std-sqrt-precision branch from 517bf62 to 785ea29 Compare September 7, 2025 11:29
@roderickvd roderickvd marked this pull request as ready for review September 7, 2025 11:31
@est31 est31 merged commit d089297 into RustAudio:master Sep 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants