<html>
<head>
<base href="http://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 --- - PowerPC long double literal conversion produces incorrectly rounded result"
href="http://llvm.org/bugs/show_bug.cgi?id=21278">21278</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>PowerPC long double literal conversion produces incorrectly rounded result
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Other
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hstong@ca.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Given
long double x = 123456.789L;
Clang produces the following:
x:
.quad 4683220299150161609 # ppc_fp128
123456.788999999999999999999999999
.quad -4786497741563401076
.size x, 16
Which, in hexadecimal is:
40fe240c9fbe76c9
bd92f1a9fbe76c8c
However, the nearest result representable in the format is 1 ulp less in the
less significant double; calculations are below.
Sign and exponent for high double:
0x3ff + floor(ln(123456789 / 1000) / ln(2)) = 40f
Significand for high double:
123456789 / 1000 * 2^(-(0x40f - 0x3ff) + 52) = 8483885939586760 + 88/125
(round to 8483885939586761)
8483885939586761 in base 16 = 1e240c9fbe76c9
High double:
40fe240c9fbe76c9
Sign and exponent for low double:
0x800 + 0x3ff + floor(ln(-(123456789 / 1000 - 0x1e240c9fbe76c9 * 2^(-52 +
(0x40f - 0x3ff)))) / ln(2)) = bd9
Significand for low double:
-(123456789 / 1000 - 0x1e240c9fbe76c9 * 2^(-52 + (0x40f - 0x3ff))) * 2^(-(0xbd9
- 0x800 - 0x3ff) + 52) = 666532744850833408/125 = 5332261958806667 + 33/125
(round to 5332261958806667)
5332261958806667 in base 16 = 12f1a9fbe76c8b
Low double:
bd92f1a9fbe76c8b
## COMMAND TO REPRODUCE:
echo "long double x = 123456.789L;" |
clang -target powerpc64-unknown-linux-gnu -S -o - -x c -
## ACTUAL OUTPUT:
.text
.file "-"
.type x,@object # @x
.data
.globl x
.align 4
x:
.quad 4683220299150161609 # ppc_fp128
123456.788999999999999999999999999
.quad -4786497741563401076
.size x, 16
.ident "clang version 3.6.0 (trunk 219523)"
## EXPECTED OUTPUT:
See issue description.
## COMPILER VERSION INFO: clang -target powerpc64-unknown-linux-gnu -v
clang version 3.6.0 (trunk 219523)
Target: powerpc64-unknown-linux-gnu
Thread model: posix</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>