diff options
author | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-25 15:16:27 +0000 |
---|---|---|
committer | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-25 15:16:27 +0000 |
commit | e90b28a5010d6cc7fcb83c69ebf71869ae1911ca (patch) | |
tree | 6eb6e13f7c1038e576c433fecfe7eea014d66df3 /gcc/sreal.c | |
parent | c70b2c00b83d52808c331a9e90f378d500ab386a (diff) | |
download | gcc-e90b28a5010d6cc7fcb83c69ebf71869ae1911ca.tar.gz |
2014-11-25 Martin Liska <mliska@suse.cz>
PR bootstrap/64050
PR ipa/64060
* sreal.c (sreal::operator+): Addition fixed.
(sreal::signedless_plus): Negative numbers are
handled correctly.
(sreal::operator-): Subtraction is fixed.
(sreal::signedless_minus): Negative numbers are
handled correctly.
* sreal.h (sreal::operator<): Equal negative numbers
are compared correctly.
(sreal::shift): New checking asserts are introduced.
Operation is fixed.
* gcc.dg/plugin/plugin.exp: New plugin.
* gcc.dg/plugin/sreal-test-1.c: New test.
* gcc.dg/plugin/sreal_plugin.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218048 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/sreal.c')
-rw-r--r-- | gcc/sreal.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/sreal.c b/gcc/sreal.c index 0337f9e540c..2b5e3ae82be 100644 --- a/gcc/sreal.c +++ b/gcc/sreal.c @@ -182,9 +182,9 @@ sreal::operator+ (const sreal &other) const { sreal tmp = -(*b_p); if (*a_p < tmp) - return signedless_minus (tmp, *a_p, false); + return signedless_minus (tmp, *a_p, true); else - return signedless_minus (*a_p, tmp, true); + return signedless_minus (*a_p, tmp, false); } gcc_checking_assert (a_p->m_negative == b_p->m_negative); @@ -203,7 +203,7 @@ sreal::signedless_plus (const sreal &a, const sreal &b, bool negative) const sreal *a_p = &a; const sreal *b_p = &b; - if (*a_p < *b_p) + if (a_p->m_exp < b_p->m_exp) std::swap (a_p, b_p); dexp = a_p->m_exp - b_p->m_exp; @@ -211,6 +211,7 @@ sreal::signedless_plus (const sreal &a, const sreal &b, bool negative) if (dexp > SREAL_BITS) { r.m_sig = a_p->m_sig; + r.m_negative = negative; return r; } @@ -248,11 +249,11 @@ sreal::operator- (const sreal &other) const /* We want to substract a smaller number from bigger for nonegative numbers. */ if (!m_negative && *this < other) - return -signedless_minus (other, *this, true); + return signedless_minus (other, *this, true); /* Example: -2 - (-3) => 3 - 2 */ if (m_negative && *this > other) - return signedless_minus (-other, -(*this), true); + return signedless_minus (-other, -(*this), false); sreal r = signedless_minus (*this, other, m_negative); @@ -274,6 +275,7 @@ sreal::signedless_minus (const sreal &a, const sreal &b, bool negative) if (dexp > SREAL_BITS) { r.m_sig = a_p->m_sig; + r.m_negative = negative; return r; } if (dexp == 0) |