Rust language adds algebraic floating-point methods

Rust language adds algebraic floating-point methods

The new algebraic methods allow optimizations on floating-point addition, subtraction, multiplication, division, and remainder operations using the algebraic properties of real numbers. The Rust team has released Rust 1.98.0, an update to the language that introduces algebraic methods for floating-point operations. Developers who have a previous version of Rust installed via rustup can update to Rust 1.98.0 by running rustup update stable. Introduced August 20, Rust 1.98.0 brings algebraic methods for addition, subtraction, multiplication, division, and remainder to the floating-point types f32 and f64. The algebraic methods allow optimizations on these operations using algebraic properties of real numbers. These optimizations are not specified, but may be similar to the kind of optimization seen with the -ffast-math option in other languages, the Rust team said. “For example, floating-point addition is not associative, so a sum like a + b + c + d must be evaluated in the left-associative order in which it is parsed, like ((a + b) + c) + d,” the Rust team noted. “If you write the same sum as a chain of algebraic_add calls, then the compiler is free to reorder it, perhaps like (a + b) + (c + d) to evaluate the partial sums simultaneously. Broader loop-vectorization is often enabled by using these algebraic methods as well.” The methods are non-deterministic, because the compiler is free to choose different optimizations, but they never cause undefined behavior, the Rust team said. Rust 1.98.0 also introduces buffered integer formatting. All primitive integer types now have a format_into method that takes a &mut NumBuffer parameter, which is a buffer large enough to hold the decimal format of any value of the type. The format_into method returns the formatted &str with a lifetime borrowed from the buffer, and bypasses much of the dynamic dispatch of buffered write! formatting, improving performance.

Original Source

Read the full article at Infoworld →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.