gcode_parse.c: join the upper and the lower formula in decfloat_to_int().

This also makes rounding more accurate with exponent > 0.
Saves another 40 bytes binary size.
This commit is contained in:
Markus Hitter 2011-04-11 01:12:53 +02:00
parent 8cf8a8a44a
commit 6896aa5236
1 changed files with 3 additions and 10 deletions

View File

@ -98,18 +98,11 @@ static int32_t decfloat_to_int(decfloat *df, uint32_t multiplicand, uint8_t divi
e--;
uint32_t rnew1 = r * (multiplicand / denominator);
if (e)
{
uint32_t rnew2 = r * (multiplicand % denominator) / denominator;
r = rnew1 + rnew2;
r = (r + powers[e] / 2) / powers[e];
}
else
{
uint32_t rnew2 = (r * (multiplicand % denominator) + (denominator / 2)) / denominator;
r = rnew1 + rnew2;
}
if (e)
r = (r + powers[e] / 2) / powers[e];
return df->sign ? -(int32_t)r : (int32_t)r;
}