24 lines
945 B
Rust
24 lines
945 B
Rust
//! Every non-negative f32, through the frame DSP's integer square root
|
|
//! (`graph::widgets::frame_sqrt`, which the interpreter, the Host program and the firmware all
|
|
//! run), against `f32::sqrt`, which IEEE 754 requires to be correctly rounded: equal bits for
|
|
//! all 2^31 of them, or the first that differs.
|
|
//!
|
|
//! ```sh
|
|
//! cargo run -q --release -p flowrs-core --example frame_sqrt_exhaustive
|
|
//! ```
|
|
|
|
use flowrs_core::graph::widgets::dsp_frame::kernels;
|
|
|
|
fn main() {
|
|
let mut checked = 0u64;
|
|
for bits in 0u32..=0x7fff_ffff {
|
|
let x = f32::from_bits(bits);
|
|
let (a, b) = (kernels::sqrt(x), x.sqrt());
|
|
let same = a.to_bits() == b.to_bits() || (a.is_nan() && b.is_nan());
|
|
assert!(same, "sqrt({x:e}) [{bits:#010x}]: {a:e} vs {b:e}");
|
|
checked += 1;
|
|
}
|
|
println!(
|
|
"frame_sqrt: all {checked} non-negative f32 values (with +inf and every NaN) agree with f32::sqrt bit for bit"
|
|
);
|
|
}
|