fix arithmetic overflow

Signed-off-by: Michael Moon <triffid.hunter@gmail.com>
This commit is contained in:
Jacky2k 2011-01-06 10:44:06 +11:00 committed by Michael Moon
parent ecc0d6e3ef
commit 19e3c24835
1 changed files with 8 additions and 4 deletions

View File

@ -60,10 +60,14 @@ int32_t decfloat_to_int(decfloat *df, int32_t multiplicand, int32_t denominator)
e--; e--;
// scale factors // scale factors
if (multiplicand != 1) // if (multiplicand != 1)
r *= multiplicand; // r *= multiplicand;
if (denominator != 1) // if (denominator != 1)
r /= denominator; // r /= denominator;
int32_t rnew1 = r * (multiplicand / denominator)
int32_t rnew2 = r * (multiplicand % denominator)
r = rnew1 + rnew2;
// sign // sign
if (df->sign) if (df->sign)