Post Reply 
(42, all flavours) Integer Division - how?
12-20-2020, 02:14 AM
Post: #46
RE: (42, all flavours) Integer Division - how?
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.

I've always used this formulation, rather than fiddling with MOD.

Is there a downside to this method, I mean in general, not specific to the 42?

- Rob

"I count on old friends to remain rational"
Visit this user's website 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? - robve - 12-20-2020 02:14 AM



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