jackmott / LinqFaster

Linq-like extension functions for Arrays, Span<T>, and List<T> that are faster and allocate less.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Different answers between SumF and SumSP

Smurf-IV opened this issue · comments

I was using SumSP and was getting an answer of 18 but on one machine (Lower spec) it consistently got 17 ???
So I had a look at the code and on the machine that get 18, and I get the following answers
(Sorry cannot give you the data set as it is embedded in the datastores)

        float lengthSPM = lengths.SumSP(MIN_STEP_FILTER_POINTS); // get 18
        float lengthSP = lengths.SumSP(); // get 13
        float lengthS = lengths.SumS(); // get 17
        float lengthF = lengths.SumF(); // get 17

floating point math is not commutative, so if you add things in different orders, you can get different answers. a+b+c+d != (a+b)+(c+d) for instance.

the order in which things get added up when you go parallel is not deterministic (depends on core count for instance) so you can get different answers. For the same reason a SIMD sum may not equal a non SIMD sum (though the SIMD will be more accurate, actually)