From 6896aa5236f2a00e751933dc130895930857f117 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 11 Apr 2011 01:12:53 +0200 Subject: [PATCH] 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. --- gcode_parse.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/gcode_parse.c b/gcode_parse.c index a72238f..07cdd45 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -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; + uint32_t rnew2 = (r * (multiplicand % denominator) + (denominator / 2)) / denominator; + r = rnew1 + rnew2; + if (e) r = (r + powers[e] / 2) / powers[e]; - } - else - { - uint32_t rnew2 = (r * (multiplicand % denominator) + (denominator / 2)) / denominator; - r = rnew1 + rnew2; - } return df->sign ? -(int32_t)r : (int32_t)r; }