4 ms·
Actually commutativity doesn't hold either, because of dealing with NaNs (at least on x86, on a quick search I can't find a reference for whether this behavior
by zwegner 12y ago
Actually commutativity doesn't hold either, because of dealing with NaNs (at least on x86, on a quick search I can't find a reference for whether this behavior is part of IEEE 754 or just implementation defined). Operations with two NaNs will give the first operand. You can see this with a quick test program:
#include <stdio.h>
int main() {
unsigned long long bits = 0x7FFC000000000000;
double x = *(double *)&bits;
bits += 1;
double y = *(double *)&bits;
double z = x + y, w = y + x;
printf("%llx %llx\n", *(unsigned long long *)&z, *(unsigned long long *)&w);
}
Of course, this probably doesn't matter for most applications.
- stephencanon 12y agoIEEE-754 says that the result “should” be one of the two input NaNs. A platform could choose to e.g. take the NaN with the smaller payload to make * and + commutative, or it could simply define away NaN payloads entirely.