[LLVMbugs] [Bug 21278] New: PowerPC long double literal conversion produces incorrectly rounded result
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Oct 14 13:07:10 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=21278
Bug ID: 21278
Summary: PowerPC long double literal conversion produces
incorrectly rounded result
Product: clang
Version: trunk
Hardware: Other
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: hstong at ca.ibm.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
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, at 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
--
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/20141014/e5a6a7ea/attachment.html>
More information about the llvm-bugs
mailing list