|
> function round(x)
> local y = math.ceil(x - 0.5)
> return x - y + y/2%1 < 1 and y or math.ceil(x)
> end
I'll take your word that it works, since you have a good
reputation for meticulous coding.
>> function round(x)
>> local ans = math.floor(x)
>> local err = x-ans
>> if err<0.5 then return ans
>> elseif err>0.5 then return ans+1
>> elseif ans%2==0 then return ans
>> else return ans+1
>> end
>> end
>
>
> Yes, that's correct (but cumbersome).
At least one person besides the author could see at a glance
that the code is correct. I'll take 'cumbersome' any day if it can
give me that.