0

I have dll which reads floating point values from binary files, makes simple calculation and gives boolean result. Each file is 8bytes length so variables are of type double ( Visual Studio 2008 ). Calculation is very simple:

if( fA < fB - ( iX * fC ) )
{
return( 1 );
}
else
{
return( 0 );
}

This dll is loaded and function is called by 2 different applications on same PC. For debug reasons values that are read from files are written to another files, calculations were split into parts and also written to files. Each app outputs same files except final result! One application gives 1, another 0. Dll compiled with /MT /fp:precise /Od options. Any ideas please?

psu
  • 111
  • 1
  • 10
  • 1
    Search the web for "every programmer floating point". – Thomas Matthews Jul 21 '13 at 18:42
  • @ThomasMatthews The resource you are alluding to, http://floating-point-gui.de/ , explains why floating-point computations are different from mathematical computations. This is not the question. The question is why a floating-point computation implemented in a DLL produces different results when used from two different applications. – Pascal Cuoq Jul 21 '13 at 20:26
  • Providing an example of the 4 floating point numbers would help. – chux - Reinstate Monica Jul 21 '13 at 22:08
  • chux, here is binary representation: fA={0x18, 0x67, 0x4d, 0xf0, 0x30, 0x7e, 0x2d, 0x40}, fB={0xdb, 0xf7, 0x7b, 0xd3, 0x56, 0xd5, 0x42, 0x40}, iX=0x28 (it's 32bit int), fC={0xee, 0xfc, 0x40, 0xf2, 0x10, 0x56, 0xe2, 0x3f} – psu Jul 22 '13 at 06:55

1 Answers1

0

Unless your DLL goes out of its way to have different paths on different architectures (for instance a 387 path and a SSE path), the only possibility is that at least one of the applications changes the FPU state. Typically, this would be the rounding mode, but in the case of the 387 FPU, it can also be the significand width at which instructions compute (“the x87 can be configured via a special configuration/status register to automatically round to single or double precision after each operation”).

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • Sure, just wanted to make sure this solution works. It does by setting fpu mode to _control87_2( _PC_53, _MCW_PC ) – psu Jul 22 '13 at 08:35