Post Reply 
(42, all flavours) Integer Division - how?
12-20-2020, 10:09 AM
Post: #49
RE: (42, all flavours) Integer Division - how?
(12-19-2020 03:14 AM)Albert Chan Wrote:  
PHP Code:
function idiv6c(ab)   -- assumed b 0
    local r 
a/b
    local q 
floor(r)
    if 
~= r then return q end
    r 
= (a%b) * 2
    
if == 0 then r % (b+bend
    
return and q-or q
end 

2 remarks:
- shouldn't that be if r== b instead of if r==0 ?
- and, a%b*2 may overflow again?

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
RE: (42, all flavours) Integer Division - how? - Werner - 12-20-2020 10:09 AM



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