Post Reply 
(42, all flavours) Integer Division - how?
12-17-2020, 12:42 PM (This post was last modified: 12-17-2020 07:28 PM by Werner.)
Post: #35
RE: (42, all flavours) Integer Division - how?
Actually that code works for Cc00 = Qq*Xx + Rr, too, save for the round-to-even cases, that are very rare.
So I can do

Code:
Qq := Cc00/Xx;
Rr := MOD(Cc00,Xx);
if FRC(Qq) >0
then Qq := INT(Qq);
else
  if Rr>0 then
    if Rr>Xx-Rr then Qq:= Qq - 1;
    elsif Rr = Xx-Rr then
    c := Xx+1;
    b := MOD(Qq,c);
    a := Rr - MOD(CC00,c);
    if NOT(a=b or a=b-c ) then Qq:=Qq - 1;
  end;
end;

and the test for Rr>0 is not necessary either

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-17-2020 12:42 PM



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