4 ms·
Is zig's optimized float mode also extremely error-prone like gcc ffastmath? Reminder: With gcc/clang, -ffastmath makes it undefined behavior to run a calculat
by ynik 3y ago
Is zig's optimized float mode also extremely error-prone like gcc ffastmath?
Reminder: With gcc/clang, -ffastmath makes it undefined behavior to run a calculation that results in an infinity or NaN. Due to the way UB works, the compiler can end up miscompiling not just the floating-point calculation, but also other code nearby (e.g. delete array bounds checks).
This is why Rust does not have any fastmath-equivalent: it would allow violating memory safety in safe code.
- dataangel 3y agoSeems like there should just be a fastmath mode that doesn't consider it UB. IIUC most of the gains come from being able to assume addition, multiplication etc are associative and commutative.