摘要 探讨算式
的计算精度问题。
例1. 已知 计算
不妨在Python下计算,则有:
若用Rust在线计算:
fn main() {
let x: f64 = 0.125e-6;
let tan_x = x.tan();
let sin_x = x.sin();
let denominator = x - (1.0 + x * x).sqrt();
let result = (tan_x - sin_x) / denominator;
println!("{}", result);
}
则有等价的输出(虽然表述形式不同):-0.0000000000000000000009793819676855232 .
然而,16位的正确结果为 -0.9765626220703239e-21(ISRealsoft 提供)。这样,二者有效数字的错误率均为 (16-2)/16 = 87.5% .
参考文献
[1] Ward Cheney, David Kincaid. Numerical Mathematics and Computing. 6th Ed. CA: Thomson Higher Education, 2008, p, 69