Post Reply 
(42, all flavours) Integer Division - how?
12-20-2020, 08:46 AM
Post: #48
RE: (42, all flavours) Integer Division - how?
(12-20-2020 02:14 AM)robve Wrote:  Using the int function (or floor function), the quotient Q and remainder R of Y/X is simply:

Q = sign(X)*int(Y/abs(X))
R = Y-Q*X

This satisfies Y=Q*X+R, 0<=R<|X|, for any Y and X!=0.

In unlimited arithmetic, yes.
But it fails when Q is rounded up, or when Q*X carries more significant digits than the maximum (12 for a 42S or 34 for Free42).

For instance:
42S: Y: 1e12 X: 6
Y: 9.8696044e21 X: 31415926536

You might consider these examples farfetched and contrived, but when you try to implement a multiprecision division (as I mentioned in one of the previous posts here), it is what you need to get right.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42, all flavours) Integer Division - how? - Werner - 12-20-2020 08:46 AM



User(s) browsing this thread: 1 Guest(s)