diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-01-25 14:15:57 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-01-25 14:20:44 -0500 |
commit | 5ca132eafaaaf2b5bffc2b696d1fa4e364ffaf0b (patch) | |
tree | f391fdc0767050e054d5da3c74d2d3b569a2817b /klippy/chelper/stepcompress.c | |
parent | 502e83725b1bbcdf684d9a99220769ca831c0164 (diff) | |
download | kutter-5ca132eafaaaf2b5bffc2b696d1fa4e364ffaf0b.tar.gz kutter-5ca132eafaaaf2b5bffc2b696d1fa4e364ffaf0b.tar.xz kutter-5ca132eafaaaf2b5bffc2b696d1fa4e364ffaf0b.zip |
stepcompress: Fix rounding error when interval=0
In the rare case where the step generation code finds an interval of
zero, it was possible for an integer division of a negative number to
cause an incorrect result. Fix that by using the idiv_up() and
idiv_down() helpers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper/stepcompress.c')
-rw-r--r-- | klippy/chelper/stepcompress.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/klippy/chelper/stepcompress.c b/klippy/chelper/stepcompress.c index 4a386d65..7b92e3db 100644 --- a/klippy/chelper/stepcompress.c +++ b/klippy/chelper/stepcompress.c @@ -115,9 +115,9 @@ compress_bisect_add(struct stepcompress *sc) int32_t nextaddfactor = nextcount*(nextcount-1)/2; int32_t c = add*nextaddfactor; if (nextmininterval*nextcount < nextpoint.minp - c) - nextmininterval = DIV_ROUND_UP(nextpoint.minp - c, nextcount); + nextmininterval = idiv_up(nextpoint.minp - c, nextcount); if (nextmaxinterval*nextcount > nextpoint.maxp - c) - nextmaxinterval = (nextpoint.maxp - c) / nextcount; + nextmaxinterval = idiv_down(nextpoint.maxp - c, nextcount); if (nextmininterval > nextmaxinterval) break; interval = nextmaxinterval; |