<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - p static_cast<int16_t>(...) has inconsistent output"
href="https://bugs.llvm.org/show_bug.cgi?id=33459">33459</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>p static_cast<int16_t>(...) has inconsistent output
</td>
</tr>
<tr>
<th>Product</th>
<td>lldb
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>lldb-dev@lists.llvm.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vince@nethacker.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>(lldb) version
lldb version 3.9.0 ( revision )
(lldb) p r_sigma_float
(const float) $11 = 0.0500000007
(correct)
(lldb) p (1.0f / (2 * r_sigma_float * r_sigma_float)) * (1<<kQ)
(float) $3 = 51199.9961
(correct)
(lldb) p static_cast<int16_t>(51199.99f)
(int16_t) $1 = 32767
Technically, this is undefined but the output here matches what g++ does so I
think it's good. Clang current returns inconsistent results. Ideally, it
would be nice for lldb to print (undefined) or be consistent with whatever
compiler you are using. I'm hoping to get clang's behavior changed:
<a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - static_cast<int16_t>(51200.0f) returns unpredictable value"
href="show_bug.cgi?id=33448">https://bugs.llvm.org/show_bug.cgi?id=33448</a>
<a href="http://eel.is/c++draft/conv.fpint#1">http://eel.is/c++draft/conv.fpint#1</a>
(lldb) p static_cast<int16_t>((1.0f / (2 * r_sigma_float * r_sigma_float)) *
(1<<kQ))
(int16_t) $2 = -14337
Again this is undefined but it is inconsistent with the previous behavior so I
would call it a bug.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>