diff --git a/gcode_parse.c b/gcode_parse.c index 7e7c4fd..65fb295 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -57,9 +57,9 @@ extern const uint32_t powers[]; // defined in sermsg.c /// convert a floating point input value into an integer with appropriate scaling. /// \param *df pointer to floating point structure that holds fp value to convert /// \param multiplicand multiply by this amount during conversion to integer -/// \param divide_by_1000 divide by 1000 during conversion to integer /// -/// lots of work has been done in exploring this function's limitations in terms of overflow and rounding +/// Tested for up to 42'000 mm (accurate), 420'000 mm (precision 10 um) and +/// 4'200'000 mm (precision 100 um). static int32_t decfloat_to_int(decfloat *df, uint32_t multiplicand) { uint32_t r = df->mantissa; uint8_t e = df->exponent; @@ -68,6 +68,13 @@ static int32_t decfloat_to_int(decfloat *df, uint32_t multiplicand) { if (e) e--; + // This raises range for mm by factor 1000 and for inches by factor 100. + // It's a bit expensive, but we should have the time while parsing. + while (e && multiplicand % 10 == 0) { + multiplicand /= 10; + e--; + } + r *= multiplicand; if (e) r = (r + powers[e] / 2) / powers[e];