Rust 1.98 speeds up floating-point math — 8x gap with C++ finally addressed

Rust 1.98 has been released, and its headline feature is the introduction of algebraic methods for floating-point types. These methods allow the compiler to perform optimizations similar to the -ffast-math flag used in C and C++ compilers.
The new algebraic methods are available for the f32 and f64 types. They cover addition, subtraction, multiplication, division, and remainder operations. What makes them special is that they permit the compiler to reorder floating-point operations using algebraic properties of real numbers — even though these properties do not strictly hold due to the limitations of floating-point representation under the IEEE 754 standard. The exact set of optimizations is not specified by the Rust language team, but developers warn that the same inputs may produce different results even within a single program run. Unsafe code must not rely on any property of the return value for soundness.
The motivation for these methods came from a 2025 issue tracking a real-world performance gap: a simple dot product computation in Rust was up to 8 times slower than the equivalent C++ code on modern x86_64 CPUs. The root cause was that the Rust compiler refused to reorder floating-point operations, which prevented effective vectorization. In C++, the -ffast-math flag enables such reordering by default in many projects, giving a significant speed advantage.
Rust's approach is more conservative: instead of a global flag that affects all floating-point operations, the new algebraic methods are explicitly invoked by the programmer. This gives developers fine-grained control over which operations can be optimized, reducing the risk of unexpected numerical behavior across the entire codebase.
Alongside the floating-point improvements, Rust 1.98 also introduces buffered integer formatting, which improves performance when formatting integers to strings. Several other minor changes and bug fixes are included in the release as well.
The new release is available via the official Rust toolchain installer. Developers can update to Rust 1.98 by running `rustup update stable`.


