News for hackers. Stuff that matters.
Re:The state of SIMD in Rust in 2025 by wtallis on Wednesday November 05, 2025 @06:19PM (#45829389)
"a+b+c" doesn't describe a unique evaluation order. You need some parentheses to disambiguate which changes are due to associativity vs commutativity. a+(b+c)=(c+b)+a should be true of floating point numbers, due to commutativity. a+(b+c)=(a+b)+c may fail due to the lack of associativity.
Re:The state of SIMD in Rust in 2025 by adastra22 on Wednesday November 05, 2025 @06:29PM (#45829477)
It is not, due to precision. Consider a=1.00000, b=-0.99999, and c=0.00000582618.
Re:The state of SIMD in Rust in 2025 by jcranmer on Wednesday November 05, 2025 @07:20PM (#45829866)
No, the two evaluations will give you exactly the same result: https://play.rust-lang.org/?version=stable&mode=debug&editio...

IEEE 754 operations are nonassociative, but they are commutative (at least if you ignore the effect of NaN payloads).

Re:The state of SIMD in Rust in 2025 by dbdr on Thursday November 06, 2025 @02:49AM (#45832592)
Is there a case involving NaN where they are not commutative? Do you mean getting a different bit-level representation of NaN?
Re:The state of SIMD in Rust in 2025 by Remnant44 on Thursday November 06, 2025 @04:04AM (#45833049)
In practical use for simd, various min/max operations. On Intel at least, they propagate nan or not based on operand order
Re:The state of SIMD in Rust in 2025 by boulos on Thursday November 06, 2025 @10:41AM (#45836420)
Also all comparisons.
Re:The state of SIMD in Rust in 2025 by jcranmer on Thursday November 06, 2025 @10:06AM (#45836082)
IEEE 754 doesn't (usually) distinguish between different NaN encodings for the purposes of semantics--if the result is a NaN, it doesn't specify which NaN the result is. Most hardware vendors implement a form of NaN propagation: when both inputs are NaN, one of the operands is returned, for example, always the left NaN is returned if both are NaN.

As a side note: all compilers I'm aware of make almost no guarantees on preserving the value of NaN payloads, hence they consider floating-point operations to be fully commutative, and there's no general way to guarantee that they evaluate in exactly the order you specified.

Re:The state of SIMD in Rust in 2025 by imtringued on Thursday November 06, 2025 @04:51AM (#45833357)
https://play.rust-lang.org/?version=stable&mode=debug&editio...

You're supposed to do (a+b) to demonstrate the effect, because floating point subtraction that results in a number near zero is sensitive to rounding (worst case, a non-zero number gets you a zero number), which can introduce a huge error when a and b are very similar numbers.

Re:The state of SIMD in Rust in 2025 by jcranmer on Thursday November 06, 2025 @09:59AM (#45835985)
When you go from (a + b) + c to a + (b + c), you're invoking the associative property, not the commutative property.

The confusion between associativity and commutativity is the entire point of this thread!

Re:The state of SIMD in Rust in 2025 by zygentoma on Wednesday November 05, 2025 @06:35PM (#45829536)
You still need to specify an evaluation order …
Re:The state of SIMD in Rust in 2025 by immibis on Wednesday November 05, 2025 @06:48PM (#45829631)
Does (1.00000+-0.99999)+0.00000582618 != 0.00000582618+(-0.99999+1.00000) ? This would disprove commutativity. But I think they're equal.