(42, all flavours) Integer Division - how?
|
12-13-2020, 08:51 PM
Post: #19
|
|||
|
|||
RE: (42, all flavours) Integer Division - how?
(12-13-2020 07:19 PM)Werner Wrote:(12-13-2020 04:21 PM)Albert Chan Wrote: Assuming q is correctly rounded (mode round-to-nearest), r = 0 or -1Only for a and b positive? I defined IDIV matching MOD behavior: a = b * IDIV(a,b) + MOD(a,b) Free42, binary and decimal, uses floor-mod: (a MOD b) has sign of b To match it, IDIV(a,b) = floor(a/b) So, above DIV is correct: floor((-4e11 - 6)/4) = floor(-1e11 - 1.5) = -1e11 - 2 Python also define it this way, see Why Python Integer Division Floors >>> a, b = -4*10**11-6, 4 >>> q, r = a//b, a%b >>> print q, r, q*b+r -100000000002 2 -400000000006 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)