Re: final message
- Posted by mattlewis (admin) May 24, 2012
- 1449 views
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