79302790

Date: 2024-12-23 10:27:10
Score: 0.5
Natty:
Report link

Both C and C++ define precision, C++11 adds more details. C++11 added the limits header file in the standard. Some defines measure mantissa bits and some measure display bytes in base 10.

C Header file: float.h

LDBL_MANT_DIG // BITs in long double MANTissa   ie: 64
DBL_MANT_DIG  // bits in double                 ie: 53

C++ Header file limits (since c++11)

std::numeric_limits<double>::digits   /* bits same as DBL_MANT_DIG */
std::numeric_limits<long double>::digits /* bits same as LDBL_MANT_DIG */ 
std::numeric_limits<double>::digits10    /* BYTES displayed base 10 */ 
std::numeric_limits<long double>::digits10 /* bytes displayed base 10 */ 

numeric_limits has other details as well. floating point might be one of two standards, one uses an extra bit. Thats a detail you can ignore if you use the defined macros. Otherwise, if you calculate, based on bits, you might be trivially off by 1/8th.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Norman Bo Graham