[llvm-bugs] [Bug 30323] New: Header "limits": const int max_digits10 calculation won't compile if "int" is 16 bit long

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 7 22:14:59 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=30323

            Bug ID: 30323
           Summary: Header "limits": const int max_digits10 calculation
                    won't compile if "int" is 16 bit long
           Product: libc++
           Version: 3.8
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: georg.ramme at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

For type float, double or long double, the calculation of max_digits10 is:
static _LIBCPP_CONSTEXPR const int  max_digits10 = 2+(digits * 30103)/100000);

This won't compile when type "int" is only 16 bit long (for example, when
compiling for target msp430), since "digits * 30103" is then out of range.
(When digits is 24, digits * 30103 is 722472 >= 32767.

As a fix, the calculation could be made as "long" and then casted to "int".
E.g.
static _LIBCPP_CONSTEXPR const int  max_digits10 = 
        static_cast<int>(2L+(static_cast<long>(digits) * 30103L)/100000L);

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160908/17a7e23d/attachment.html>


More information about the llvm-bugs mailing list