Given that the numbers are relatively small (~ -1 to ~ 1) and are floats and randomly generated, can you get 'floating point invalid operation' by adding too many of them? I am asking because that's what apparently happens in my program right now and very rarely too. Also, how does one disable (or avoid) this exception?
Just in case, my compiler is gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.1.0.
EDIT As requested I am providing the code. However, the addition of floats causing the error is only my conjecture, that's why I came here, to find out if that could be my problem. If I run code below, is it reasonable that I can get the error?
float sum = 0, add = 0;
add = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
if (rand() % 2) add *= -1;
sum += add;
The IEEE 754 standard defines the following situations in which an “invalid operation” floating-point exception occurs:
Your example code will not trigger any of those cases, so the problem would be elsewhere in your code.