Post Reply 
(42, all flavours) Integer Division - how?
12-24-2020, 11:12 AM
Post: #57
RE: (42, all flavours) Integer Division - how?
Since c ≠ 0, or 5 (mod 10), we can rewrite the equality as:

0 ≡ (2*Qq ± 1) * (2c) (mod 10), where c = last non-zero decimal digit of Rr
0 ≡ (2*Qq ± 1) * c (mod 5)

+1 case: Qq ≡ 2 (mod 5)
−1 case: Qq ≡ 3 (mod 5)

But, -1 case should return Qq-1.
This meant half-way case floor-divide quotient always in 5n+2 form Smile

PHP Code:
function idiv7b(Cc00Xx)
    
local QqRr d2(Cc00/Xx), Cc00%Xx
    local c 
floor(Qq)
    if 
Qq ~= c then return c end
    
if Rr Xx-Rr then return c end     -- Cc00/Xx rounded-down to c
    
if Rr Xx-Rr then return c-1 end   -- Cc00/Xx rounded-up to c
    
return - (c-2)%5                  -- halfway case
end 
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? - Albert Chan - 12-24-2020 11:12 AM



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