include/limits compile time overflow

DJ Delorie dj@redhat.com
Tue Nov 2 23:32:00 GMT 2010


On 16-bit targets, include/limits fails to compile because this line:

      static constexpr int max_digits10
         = __glibcxx_max_digits10 (__DBL_MANT_DIG__);

results in computing 53 * 643 = 34,079, which exceeds 32767.  GCC then
complains that the result is not computable at compile time.

The math comes from this:

// The fraction 643/2136 approximates log10(2) to 7 significant digits.
#define __glibcxx_digits10(T) \
  (__glibcxx_digits (T) * 643 / 2136)

#define __glibcxx_max_digits10(T) \
  (2 + (T) * 643 / 2136)


Can we use smaller numbers, or switch the 643 to 643L to appease gcc?



More information about the Libstdc++ mailing list