diff options
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; } |