gcode_parse.c: review decfloat_to_int() yet again.
This time, raise range at the cost of some precision for the newly explored areas.
This commit is contained in:
parent
88236ba698
commit
5a9a134ae4
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Reference in New Issue