(42S) Quotient and Remainder
04-05-2023, 03:55 PM (This post was last modified: 04-05-2023 04:52 PM by Werner.)
Post: #5
 Werner Senior Member Posts: 891 Joined: Dec 2013
RE: (42S) Quotient and Remainder
So, to work for negative X and/or Y, the algorithm should become:
(changes in red)

t := X/Y;
Q := FLOOR(t);
R := MOD(Y,X);
if t#Q then return(R,Q);
t := X - R;
if ABS(t)<ABS(R) then Q:= Q - 1;
if t=R then Q:= Q - MOD(FLOOR(MOD(Y,X*10)/X),2); /* equals IP(MOD(MOD(Y,X*10)/X,2)) */
return(R,Q);

Sigh. Back to the drawing board.[update: done]
Werner

41CVâ€ ,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
 « Next Oldest | Next Newest »

 Messages In This Thread (42S) Quotient and Remainder - Werner - 04-05-2023, 09:38 AM RE: (42S) Quotient and Remainder - Albert Chan - 04-05-2023, 12:39 PM RE: (42S) Quotient and Remainder - Werner - 04-05-2023, 01:11 PM RE: (42S) Quotient and Remainder - Albert Chan - 04-05-2023, 01:48 PM RE: (42S) Quotient and Remainder - Werner - 04-05-2023 03:55 PM RE: (42S) Quotient and Remainder - Albert Chan - 04-06-2023, 12:03 AM RE: (42S) Quotient and Remainder - Albert Chan - 04-06-2023, 02:55 PM

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