Post Reply 
(42S) Quotient and Remainder
04-05-2023, 01:11 PM
Post: #3
RE: (42S) Quotient and Remainder
(04-05-2023 12:39 PM)Albert Chan Wrote:  >>> Y, X = 8*10**11+2, 4
>>> divmod(-Y, X)
(-200000000001L, 2L)
>>> divmod(Y, -X)
(-200000000001L, -2L)
Hi Albert,
My RQ routine matches the results above? remark that I do use
Q:= Q - MOD(FLOOR(MOD(Y,X*10)/X),2);
but I switched FLOOR and MOD around, then I could use IP:
Q := Q - IP(MOD(MOD(Y,X*10)/X,2)) ;

the results of MOD(Y,X*10)/X and the corresponding adjustment of Q (0 or 1) are
-3.5 - 0
-2.5 - 1
-1.5 - 0
-0.5 - 1
0.5 - 0
1.5 - 1
2.5 - 0

whether you now do MOD(FLOOR(X),2) or IP(MOD(X,2)) is the same.
ah but the initial IP should also be FLOOR then I see.
(don't get me wrong, but your explanations are sometimes a bit short, and I don't understand, or understand wrongly ;-)

I wanted to:
- use only the stack
- return X in LASTX
- be fast for simple cases, exceptions last.

That ruled out many of your suggestion algorithms, eg the one with remainder, or FMA.
I still have to do the Free42/DM42 one where I will be able to use FMA;

I will correct the routines, thanks

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
(42S) Quotient and Remainder - Werner - 04-05-2023, 09:38 AM
RE: (42S) Quotient and Remainder - Werner - 04-05-2023 01:11 PM
RE: (42S) Quotient and Remainder - Werner - 04-05-2023, 03:55 PM



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