When you print a double , you often have to print many, many numbers before printing the exact double value. You can accurately print a double . For example, double closest to 1/3 has the value:
0.333333333333333314829616256247390992939472198486328125
Printing this value requires exactly 54 digits after the decimal point. But people say double has about 16 digits of precision. What gives?
When you say that double has 16 digits of precision, that means you need at least 16 digits to double survive both ways. That is, the following process saves the input data:
double -> 16 digit decimal -> double
Thus, additional numbers minus 16 are not necessarily garbage, they are just superfluous. And according to the standard, they can be almost any - as long as reading the result will give you the same double back.
Summary: I assume that your standard Linux library prints the exact double value, and the Windows library truncates the result. Both actions are permitted by the standard.
You almost certainly don't need the exact double value anyway, since the arithmetic of floating point numbers is usually inaccurate.
source share