c++ - Precision error in double -
a large double value gets changed when printed %lf values upto following combination gives proper results 9 digits before decimal / 6 digits after decimal e.g. of value 9 digits before decimal printed %lf input : 3435537287.32 output : 3435537287.320000
once increase digits before decimal 10, values printed %lf adds garbage value. e.g. of value 10 digits before decimal printed %lf input : 34355372871.3487 output : 34355372871.348701 can see above output input value changed.
is there compile time option g++/xlc++ can used 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 precision of double. double stored 64 bits (8bytes).
(http://en.wikipedia.org/wiki/double-precision_floating-point_format)
it uses 52 bits mantissa, 1 bit signal , 11 bits exponent.
then, 52 bits mantissa gives 15–17 significant decimal digits precision.
Comments
Post a Comment