Urgent.News

What's breaking now, across thousands of outlets.

Editions

Tech

Rust 1.98 Adds Algebraic Floating-Point Methods Akin To "-ffast-math"

Rust 1.98 released today and is headlined the debut of new algebraic floating-point methods...

Rust programming language version 1.98 has introduced new algebraic methods for floating-point numbers, namely f32 and f64. These methods are designed to optimize floating-point operations like addition, subtraction, multiplication, division, and remainder. By utilizing algebraic properties of real numbers, the compiler can reorder these operations for better performance, similar to the -ffast-math optimization found in other languages.

For instance, a sum calculation like a + b + c + d would typically be evaluated in a left-associative manner ((a + b) + c) + d. However, using the new algebraic methods, the compiler can reorder the calculation, perhaps to (a + b) + (c + d), evaluating partial sums simultaneously. This reordering can also enable broader loop-vectorization, a technique that boosts performance in loops.

It's important to note that these algebraic methods are non-deterministic, meaning the compiler may choose different optimizations each time the code is compiled. As a result, the same inputs could yield different outputs within a single program run. Unsafe code should never rely on the return value's property for soundness, but the Rust implementations strive to strike a reasonable balance between performance and result accuracy.

Written by urgent.news from Phoronix's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at phoronix.com →

More in Tech

More from Thursday 20 August →