0
double a = 1E100
printf("%f", a);

It seems to be printing a different value other than 1 followed by a 100 zeros:

10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104

What might be the problem here?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Giridhar
  • 155
  • 1
  • 8
  • `1E100` cannot be represented exactly in the bits of a double. Consequently, printing it yields something close to, but not exactly the same as `1E100`. – Paul Ogilvie Jan 21 '20 at 14:00
  • So what is the maximum degree of precision for a double number? – Giridhar Jan 21 '20 at 14:02
  • 1
    A double can store up to about 17 decimal digits. After that, the values become meaningless. – Jonathan Leffler Jan 21 '20 at 14:06
  • See [Why Powers of Ten Up to 10²² Are Exact As Doubles](https://www.exploringbinary.com/why-powers-of-ten-up-to-10-to-the-22-are-exact-as-doubles/). Powers larger than that can't be represented exactly – phuclv Jan 21 '20 at 14:33

1 Answers1

0

The double type, assuming it uses IEEE 754 double precision floating point representation, only holds about 16 decimal digits of precision.

So any decimal digits after that will only be an approximate value, i.e. the closest value to 1E100 that it can represent.

dbush
  • 205,898
  • 23
  • 218
  • 273