3 ms·
> In C++, you can get the former limit using std::numeric_limits<double>::digits10, and the latter using std::numeric_limits<double>::max_digits10. Also, via G
by kazinator 11y ago
> In C++, you can get the former limit using std::numeric_limits<double>::digits10, and the latter using std::numeric_limits<double>::max_digits10.
Also, via GCC specific constants:
$ echo | gcc -E -dM - | grep -E '(FLT|DBL).*DIG'
#define __DBL_DIG__ 15
#define __FLT_MANT_DIG__ 24
#define __LDBL_MANT_DIG__ 64
#define __FLT_DIG__ 6
#define __DBL_MANT_DIG__ 53
#define __DBL_DECIMAL_DIG__ 17
#define __LDBL_DIG__ 18
#define __FLT_DECIMAL_DIG__ 9
__DBL_DIG__ versus __DBL_DECIMAL_DIG__. Useful to know.
__DBL_DECIMAL_DIG__ corresponds to DBL_DECIMAL_DIG which was added to C in C11.
In C90 or C99 we can do some hack like:
#if DBL_DECIMAL_DIG
use this
#elif __DBL_DECIMAL_DIG__
use this from gcc.
#else
fall back on DBL_DIG + 2
#endif