use la_stack::prelude::*;
fn main() -> Result<(), LaError> {
let perturbation = f64::from_bits(0x3CD0_0000_0000_0000); let m = Matrix::<3>::try_from_rows([
[1.0 + perturbation, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
])?;
let Some(det_f64_approx) = m.det_direct()? else {
unreachable!("D=3 is supported by det_direct");
};
let det_exact = m.det_exact()?;
let det_exact_as_f64 = m.det_exact_f64()?;
println!("Near-singular 3×3 matrix (perturbation = 2^-50 ≈ {perturbation:.2e}):");
for r in 0..3 {
print!(" [");
for c in 0..3 {
if c > 0 {
print!(", ");
}
print!("{:22.18}", m.get_checked(r, c)?);
}
println!("]");
}
println!();
println!("f64 det_direct() = {det_f64_approx:+.6e}");
println!("det_exact() = {det_exact}");
println!("det_exact_f64() = {det_exact_as_f64:+.6e}");
println!();
println!("The exact determinant is −3/2^50 ≈ −2.66e-15.");
Ok(())
}