diff options
author | Jan Hubicka <jh@suse.cz> | 2018-08-29 14:21:28 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2018-08-29 12:21:28 +0000 |
commit | 7a1ce63278c4d26ccfb0db3459545aa6d24f16fc (patch) | |
tree | 8ac79114f61ecfd6d551f470a979eee3750f4e23 /gcc/sreal.c | |
parent | 9ed6dbeeb285a010d4ab1e437cf4e2f7136dcc17 (diff) | |
download | gcc-7a1ce63278c4d26ccfb0db3459545aa6d24f16fc.zip gcc-7a1ce63278c4d26ccfb0db3459545aa6d24f16fc.tar.gz gcc-7a1ce63278c4d26ccfb0db3459545aa6d24f16fc.tar.bz2 |
sreal.h (normalize, [...]): Add new_sig/new_exp parameters.
* sreal.h (normalize, normalize_up, normalize_down): Add new_sig/new_exp
parameters.
(sreal constructor): Update.
* sreal.c (sreal:operator+, sreal:operator-, sreal:operator*,
sreal:operator/): Update.
From-SVN: r263952
Diffstat (limited to 'gcc/sreal.c')
-rw-r--r-- | gcc/sreal.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/gcc/sreal.c b/gcc/sreal.c index 950937a..925b065 100644 --- a/gcc/sreal.c +++ b/gcc/sreal.c @@ -138,7 +138,8 @@ sreal sreal::operator+ (const sreal &other) const { int dexp; - sreal tmp, r; + sreal tmp; + int64_t r_sig, r_exp; const sreal *a_p = this, *b_p = &other, *bb; @@ -146,10 +147,14 @@ sreal::operator+ (const sreal &other) const std::swap (a_p, b_p); dexp = a_p->m_exp - b_p->m_exp; - r.m_exp = a_p->m_exp; + r_exp = a_p->m_exp; if (dexp > SREAL_BITS) { - r.m_sig = a_p->m_sig; + r_sig = a_p->m_sig; + + sreal r; + r.m_sig = r_sig; + r.m_exp = r_exp; return r; } @@ -162,8 +167,8 @@ sreal::operator+ (const sreal &other) const bb = &tmp; } - r.m_sig = a_p->m_sig + bb->m_sig; - r.normalize (); + r_sig = a_p->m_sig + bb->m_sig; + sreal r (r_sig, r_exp); return r; } @@ -174,7 +179,8 @@ sreal sreal::operator- (const sreal &other) const { int dexp; - sreal tmp, r; + sreal tmp; + int64_t r_sig, r_exp; const sreal *bb; const sreal *a_p = this, *b_p = &other; @@ -186,10 +192,14 @@ sreal::operator- (const sreal &other) const } dexp = a_p->m_exp - b_p->m_exp; - r.m_exp = a_p->m_exp; + r_exp = a_p->m_exp; if (dexp > SREAL_BITS) { - r.m_sig = sign * a_p->m_sig; + r_sig = sign * a_p->m_sig; + + sreal r; + r.m_sig = r_sig; + r.m_exp = r_exp; return r; } if (dexp == 0) @@ -201,8 +211,8 @@ sreal::operator- (const sreal &other) const bb = &tmp; } - r.m_sig = sign * (a_p->m_sig - bb->m_sig); - r.normalize (); + r_sig = sign * ((int64_t) a_p->m_sig - bb->m_sig); + sreal r (r_sig, r_exp); return r; } @@ -212,17 +222,14 @@ sreal sreal::operator* (const sreal &other) const { sreal r; - if (absu_hwi (m_sig) < SREAL_MIN_SIG || absu_hwi (other.m_sig) < SREAL_MIN_SIG) + if (absu_hwi (m_sig) < SREAL_MIN_SIG + || absu_hwi (other.m_sig) < SREAL_MIN_SIG) { r.m_sig = 0; r.m_exp = -SREAL_MAX_EXP; } else - { - r.m_sig = m_sig * other.m_sig; - r.m_exp = m_exp + other.m_exp; - r.normalize (); - } + r.normalize (m_sig * (int64_t) other.m_sig, m_exp + other.m_exp); return r; } @@ -233,11 +240,9 @@ sreal sreal::operator/ (const sreal &other) const { gcc_checking_assert (other.m_sig != 0); - sreal r; - r.m_sig - = SREAL_SIGN (m_sig) * (SREAL_ABS (m_sig) << SREAL_PART_BITS) / other.m_sig; - r.m_exp = m_exp - other.m_exp - SREAL_PART_BITS; - r.normalize (); + sreal r (SREAL_SIGN (m_sig) + * ((int64_t)SREAL_ABS (m_sig) << SREAL_PART_BITS) / other.m_sig, + m_exp - other.m_exp - SREAL_PART_BITS); return r; } |