diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2015-06-23 20:24:53 +0000 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2015-06-23 20:24:53 +0000 |
commit | 704d41254ed70ee30a22e4e757e5a1d420e76cfc (patch) | |
tree | 2c217eeb40739f17d2e9a7ceb6b60ab12a3e1d58 /lib/builtins/fp_trunc_impl.inc | |
parent | a5665a07e4194bb5468896ab533150d5e6664a16 (diff) |
Fix incorrect truncation at the overflow boundary
Summary:
This patch fixes incorrect truncation when the input wider value is
exactly 2^dstBits. For that value, the overflow to infinity is not
correctly handled. The fix is to replace a strict '>' with '>='.
Currently,
__truncdfsf2(340282366900000000000000000000000000000.0) returns infinity
__truncdfsf2(340282366920938463463374607431768211456.0) returns 0
__truncdfsf2(400000000000000000000000000000000000000.0) returns infinity
Likewise, __truncdfhf2 and __truncsfhf2 (and consequently gnu_f2h_ieee)
are discontinuous at 65536.0.
This patch adds tests for all three cases, along with adding a missing
header include to fp_test.h.
Reviewers: joerg, ab, srhines
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D10594
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@240450 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/fp_trunc_impl.inc')
-rw-r--r-- | lib/builtins/fp_trunc_impl.inc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/builtins/fp_trunc_impl.inc b/lib/builtins/fp_trunc_impl.inc index 21bffae02..372e8d601 100644 --- a/lib/builtins/fp_trunc_impl.inc +++ b/lib/builtins/fp_trunc_impl.inc @@ -99,7 +99,7 @@ static inline dst_t __truncXfYf2__(src_t a) { absResult |= dstQNaN; absResult |= ((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode; } - else if (aAbs > overflow) { + else if (aAbs >= overflow) { // a overflows to infinity. absResult = (dst_rep_t)dstInfExp << dstSigBits; } |