3 ms·
”you’ll get the same results for accumulate and reduce for a vector of integers (when doing a sum), but you might get a slight difference for a vector of floats
by Someone 8y ago
”you’ll get the same results for accumulate and reduce for a vector of integers (when doing a sum), but you might get a slight difference for a vector of floats or doubles. That’s because floating point operations are not associative.”
That’s incorrect. Addition of int isn’t associative in C++, either. For example
INT_MAX + (1 + -1) = INT_MAX
but
(INT_MAX + 1) + -1
is undefined.
- reikonomusha 8y agoCan you give an example of non-associative integer arithmetic where both interpretations are defined but differ in value? This is the case with floats.