use la_stack::prelude::*;
fn main() {
let perturbation = f64::from_bits(0x3CD0_0000_0000_0000); let m = Matrix::<3>::from_rows([
[1.0 + perturbation, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]);
let det_f64_approx = m.det_direct().unwrap();
let det_exact = m.det_exact().unwrap();
let det_exact_as_f64 = m.det_exact_f64().unwrap();
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(r, c).unwrap());
}
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.");
}