2

According to my understanding (about what I read on the Internet), it seems that std::numeric_limits<double>::digits10 (which for double is equal to 15) represent the number of digits a double can handle, for instance 1.23456789012345 but not 1.234567890123456

On the other hand, double-precision floating-point format range will go until 1.8*10^+308, which seems to represent a number which not hold only on 15 digits.

Where is the incoherence?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145

3 Answers3

4

... std::numeric_limits<double>::digits10 (which for double is equal to 15) represent the number of digits a double can handle...

More precisely it's the number of significand digits it can store without loss of precision.

Example in Python:

1e15 == 1e15 + 1
False 

1e16 == 1e16 + 1
True # loss of precision
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
1

std::numeric_limits::digits10: Number of digits (in decimal base) that can be represented without change.

Denis Ermolin
  • 5,530
  • 6
  • 27
  • 44
1

The one is significant digits. The other is the range of numbers representable. So, you can have:

1.23456789012345*10^308

but not

1.234567890123456*10^308

which shows both significant digits 15 and the range 10^308, which can be represented.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198