A large double value gets changed when printed with %Lf Values upto the following combination gives proper results 9 digits before decimal / 6 digits after decimal e.g. of a value with 9 digits before decimal printed with %Lf Input : 3435537287.32 Output : 3435537287.320000
Once I increase the digits before decimal to 10, the values printed with %Lf adds garbage value. e.g. of a value with 10 digits before decimal printed with %Lf Input : 34355372871.3487 Output : 34355372871.348701 As you can see from the above output the input value is changed.
Is there any compile time option for g++/xlc++ that can be used so that the value is'nt changed?
::Code Snippet::
double d2 = 34355372871.3487;
double d4 = 3435537287.3487;
printf("d2 = %lf\n", d2);
printf("d4 = %lf\n", d4);
Thanks, Hudson
It is the precision of the double. The double is stored with 64 bits (8bytes).
(http://en.wikipedia.org/wiki/Double-precision_floating-point_format)
It uses 52 bits for a mantissa, 1 bit for the signal and 11 bits for the exponent.
Then, the 52 bits mantissa gives a 15–17 significant decimal digits precision.