Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significant decimal digits of double?

What does the C/C++-Standard guarantee about the minimum significant decimal digits of a double?

The C++ standard actually says in a footnote of § 18.3.2.4/10 this is equivalent to DBL_DIG as defined in the C standard. But I can't find anything about a minimum value in the C standard.

So, what is the minimum value of one of the following?

  • std::numeric_limits<double>::digits10
  • DBL_MANT_DIG edit: No, DBL_DIG
like image 460
helami Avatar asked Jan 08 '13 23:01

helami


1 Answers

You won't find it in the C++ standard, because C++ defers to the C standard on this one. For decimal digits, the minimum values are:

FLT_DIG   6
DBL_DIG  10
LDBL_DIG 10

So, 6 digits for float, and 10 for double and long double. (This is the number of digits for which it is guaranteed that a conversion from text to the type and back will result in the same value.)

Note that DBL_MANT_DIG corresponds to the number of digits in the base, thus usually the number of binary digits, and not the number of decimal digits.

like image 121
James Kanze Avatar answered Sep 21 '22 05:09

James Kanze