My C++ program calculates some floating-point number x and prints it:
cout << x;
It is important to me that the output be the same in all computers. Since "all" is very broad, let's focus on the following:
- different compilers from among g++ 6/7/8, clang++ 5/6;
- different Linux systems - Ubuntu 16.04/18.04;
- stand-alone Linux vs. Windows-subsystem Linux;
- different hardware - Intel vs. AMD with different specs.
Is the output guaranteed to be the same in all the above combinations?
If not, can I guarantee identical output by lowering the precision, e.g:
cout << setprecision(4) << x;
? If not, what more can I do to have consistent output across machines?