Rust issue #21690 talks about adding imprecise floating point operations. Linked from that issue is the addition of intrinsics that allow you to opt into looser rules on a per operation basis. For example, fadd_fast
:
pub unsafe extern "rust-intrinsic" fn fadd_fast<T>(a: T, b: T) -> T
Using intrinsics requires a nightly compiler and unsafe code:
#![feature(core_intrinsics)]
use std::intrinsics::fadd_fast;
fn main() {
let result = unsafe { fadd_fast(42.0, 31.0) };
println!("{}", result);
}
Ultimately, this is a much better design than the all-or-nothing solution of a command line flag. Who knows if there is some floating point calculation that is critical to not use fast math, buried deep in your program? That doesn't help you when trying to compare against a C program that chose that, however!