<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Header "limits": const int max_digits10 calculation won't compile if "int" is 16 bit long"
href="https://llvm.org/bugs/show_bug.cgi?id=30323">30323</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Header "limits": const int max_digits10 calculation won't compile if "int" is 16 bit long
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>georg.ramme@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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);</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>