My problem was caused by a 3rd party library that apparently leaves behind side-effects with floating-point calculation. The way this was solved for me was to ensure that the floating point state is always reset when cleaning up the use of this particular 3rd party library.
After solving the problem, I found a good description of the problem on this page:
http://www.cognaxon.com/index.php?page=wsqlib_NETnotes#2Here's some paraphrased code from my fix:
// Need this DllImport statement to reset the floating point register below
[DllImport("msvcr71.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int _controlfp(int n, int mask);
void useThirdPartyWithFPSideEffects() {
try {
//use the library
}
catch (Exception ex) {
//do what you need to do
}
finally {
//misc cleanup
//reset the floating point register to avoid fp side-effect of library
_controlfp(0x9001F, 0xFFFFF); // restore floating-point register to default value required by .NET Framework
}
}