Re: round

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

"Carl R. White" wrote:
>
> I just can't resist threads like this... smile
>
> Rolf said:
> function round_gm(atom x) -- Round to greatest magnitude
>     if x < 0 then
>         return floor(x - 0.5)
>     else
>         return floor(x + 0.5)
>     end if
> end function
>
> Rolf's function 'Carl'-ised smile
> function round_gm(object x) -- Round to greatest magnitude
>     return floor(x-.5)*(x<0)+floor(x+.5)*(x>0)
> end function
>
> Carl

Carl, my round() or round_gm() is wrong!! round_gm(-2) returns -3, not
-2 !

"Lewis Townsend" wrote:

>
> I think this will do what you want if I'm understanding your
> question correctly:
>
> function round (object x)
>   return floor (x + 0.5)
> end function

and this is correct.

Have a nice day, Rolf

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

Search



Quick Links

User menu

Not signed in.

Misc Menu