(42, all flavours) Integer Division - how?
|
12-14-2020, 08:04 AM
(This post was last modified: 12-14-2020 08:08 AM by Albert Chan.)
Post: #24
|
|||
|
|||
RE: (42, all flavours) Integer Division - how?
(12-14-2020 06:59 AM)Werner Wrote: using floor(q) now, and the 'correct or not' approach: I started with q = floor(a/b), then correct, but it is not necessary. You can use round(a/b), ceil(a/b), IP(a/b), ... it does not matter. The correction, r is still limited to 0, -1 Example, say we use ceil(a/b) for initial q a/b = 10 - ε → q = 10 → r = -1 a/b = 10 +ε → q = 11 → r = -1 What if a/b = 10 ± ε, because of round-to-nearest, get rounded to exactly 10 ? It is OK. For interger, round/ceil/floor/IP does nothing to it. Since edge case work, so is the rest ... |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)