Question

I have used this :

  long double f =79228162514264337593543950336.0;//maximum ; 2 ^ 96 because f is 12 bytes
  cout.precision(30);
  cout<<f;

But some numbers turns wrong . why ?

Was it helpful?

Solution

What size of long double does your implementation provide (or, equivalently, what value does it show for LDBL_DIGITS)? It's often an 80-bit type with ~20 significant (decimal) digits. Note, in particular, that a floating point type will be divided between a mantissa (significand) and an exponent, so if it's 12 bytes overall, it will not have a 12-bit significand, so you can't expect to see 12 bytes worth of precision.

OTHER TIPS

The correct suffix for long double literals is L:

long double f =79228162514264337593543950336.0L;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top