We are working on a scientifical related product which is most sensitive towards mathematical functions (even 7th decimal place chang can cause considereble differences in the output values). We’ve observed that the trignometric functions are behaving differently in Visual C++ 2003 and Visual C++ 2005 versions. We've recently upgraded IDE from VS2003 to VS2005 and compiled the unmanaged vc++ code in both versions.
To explain this in detail, please consider the following console application and compile it in both 2003 and 2005 versions.
Expand|Select|Wrap|Line Numbers
- // CosSinDemo.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <math.h>
- const float PI = 3.1415926535f;
- const float PI_OVER_180 = PI / 180.0f;
- int _tmain(int argc, _TCHAR* argv[])
- {
- static double fDummy1 = 0;
- static double fDummy2 = 0;
- float fDiffLat = -0.19629669; //
- float fDiffLon = 0.060424805;
- fDummy1 = cos( fDiffLon * PI_OVER_180);
- fDummy2 = cos( -fDiffLat* PI_OVER_180);
- printf("fDummy1 - %3.20f\nfDummy2 - %3.20f", fDummy1, fDummy2);
- return 0;
- }
- output with VS2005:
- fDummy1 - 0.99999946355819702000
- fDummy2 - 0.99999415874481201000
- output with VS2003:
- fDummy1 - 0.99999944389707407000
- fDummy2 - 0.99999413118713976000
Currently we've made Floating point model as /fp:precise in VS2005, could you please someone help me out on how to make VS2005 cos/sin functions behave same as was there in 2003 version.