-->
Page 1 of 1

Negative number integer division

PostPosted: Fri Jan 15, 2016 11:53 am
by amelia
My Nodemcu build: nodemcu-master-9-modules-2016-01-09-07-57-31-integer

Positive integer OK: 234567 / 10000 -> 23
Negative integer: -234567 / 10000 -> -24

Why rounding? and only for negative number!
If I want to round, I do it before the division: 234567 + 5555 or -234567 + -5555.

amelia

Re: Negative number integer division

PostPosted: Tue Jan 19, 2016 5:47 am
by TerryE
It's not rounding, just truncating towards minus infinity. This way the remainder is a positive integer

-24 * 10000 + 5433 = -234567