When I execute a simple x64 application with the following code, I get different results on Windows PCs with a i7-3770 and i7-4790 CPU.
#include <cmath>
#include <iostream>
#include <limits>
void main()
{
double val = exp(-10.240990982718174);
std::cout.precision(std::numeric_limits<double>::max_digits10);
std::cout << val;
}
Result on i7-3770:
3.5677476354876406e-05
Result on i7-4790:
3.5677476354876413e-05
When I modify the code to call
unsigned int control_word;
_controlfp_s(&control_word, _RC_UP, MCW_RC);
before the exp function call, both CPUs deliver the same results.
My questions:
- Does anyone have an idea for the reason of the differences between the i7-3770 and i7-4790?
- Is there a way to set the floating point precision or consistency in a Visual Studio 2015/2017 C++ project for the whole project and not only for the following function call? The "Floating Point Model" setting (/fp) does not have any influence on the results here.
main
returns int, not void – Registered_RC_UP
is not the default, it is_RC_NEAR
. So whatever machine you consider the "good" one is actually the troublemaker. Hunting for that DLL can keep you busy for a while. It is the kind of problem that a disk format tends to solve a lot quicker, especially when it isn't you that has to do it. – Specialtysin(45)
andcos(45)
giving different results – Torticollisvoid main()
is prohibited in C++ and C although it's allowed in free-standing C implementations – Torticollisexp
precision between Mac OS and Windows – Torticollis