Aggressive optimizing compilers may algebraically optimize Kahan's algorithm (and others) which may results invalid results. While compilers generally do not optimize math this way, users may still activate flags that enable this dangerous behavior.
We might be able to test for this as follows:
- have some global variable get initialized by our own
test_math() before main() runs
test_math() checks for correct functioning of the algorithms and throws an exception if not
I'm still not sure if this is a solution because compilers may optimize initialization code differently or not at all.
Does anyone have any ideas?