-2

http://en.wikipedia.org/wiki/Double-precision_floating-point_format say that double can handle 16 digits of precision to the right part of the number, is digits10 show this number ?

Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
  • 2
    Did you see here http://stackoverflow.com/questions/747470/what-is-the-meaning-of-numeric-limitsdoubledigits10 ? – alestanis Oct 27 '12 at 19:16
  • yes but I'm a little bit suprised because it seems digits10 show the number to the left, and wikipedia says that number of digits to the right its 15/16, so I arrive to the conclusion that both right and left side of a double precision number can handle 15 or 16 digits ?that's weird – Guillaume Paris Oct 27 '12 at 19:19
  • all right I just wanted to have this confirmation – Guillaume Paris Oct 27 '12 at 19:22

2 Answers2

5

std::numeric_limits<T>::digit10 is the number of decimal digits you can get back when converting a string with a decimal value to T and back to a string again. The count starts at the most significant non-zero digit, independent of where the decimal point is located (as long as you don't conflict with the range restrictions of T, of course). That is, leading and trailing zeros don't matter.

legends2k
  • 31,634
  • 25
  • 118
  • 222
Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
  • std::string str = "12345679012.124678"; double back = boost::lexical_cast( str ); std::string strs =boost::lexical_cast( back ); – Guillaume Paris Oct 29 '12 at 14:51
  • in my above example there is no loss but number's significand digits is greater than std::numeric_limits::digit10 – Guillaume Paris Oct 29 '12 at 14:52
  • The `digits10` works for all values. If you go lucky you can get up to `digits` decimal digits right: Any number which can be represented as (-1)_sign_ * _mantissa_ * 2 _exponent_ can be exact (as long as you stay within the bounds of what can be represented). – Dietmar Kühl Oct 29 '12 at 15:52
  • just a doubt about your sentence: "The count starts at the BIGGEST non-zero digit" at the first or the biggest ? – Guillaume Paris Oct 30 '12 at 10:35
  • I should have written "most significant non-zero digit" but failed to come up with the term. – Dietmar Kühl Oct 30 '12 at 12:07
  • Fixed now! Thanks for the answer. – legends2k Aug 28 '15 at 02:33
3

Actually it's just the number of meaningful digits. Point. You can have 12345678901234.5 or 0.0000123456789012345.

alestanis
  • 21,519
  • 4
  • 48
  • 67
  • 1
    so 0 are not taking into account into this 15 digits ? even if not at the end – Guillaume Paris Oct 27 '12 at 19:28
  • 1
    Nope :) A double is some digits, and a power of ten, so your digits are 123456789012345, and they can be multiplied by 10e-15 or by 10e18, doesn't change anything in precision – alestanis Oct 27 '12 at 19:29