Re: final message

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...

And mine would more like ...

public function intdiv(object a, object b, integer behave = 1) 
    object t 
    t = abs(a) / abs(b) 
    switch behave do 
       case -1 then 
           return floor(t) 
       case 0 then 
           return round(t) 
       case 1 then 
           return ceil(t) 
       case else 
           fail("Unknown behaviour requested") 
    end switch 
end function 
? intdiv(-8, -3, 1) --> 3 
? intdiv(-8, -3, 0) --> 3 
? intdiv(-8, -3,-1) --> 2 

I can see the value in different rounding methods, but the sign handling here seems wrong, as I would expect:

intdiv(-8, 3, 0) --> -2 

Actually, to correct my earlier statement...instead of floor(), I think trunc() is more appropriate, as it does what I would expect integer division to do.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu