Re: simple eurphoria question
- Posted by c.k.lester <euphoric at cklester.com> Dec 07, 2006
- 719 views
Larry Miller wrote: > Mike Nelson wrote: > > c.k.lester wrote: > > > I wrote a function just for this purpose. It's called > > > round_this_number_toward_zero_remember_that_negative_numbers_are_screwy(). > > > I sometimes wonder if it's worth typing all that out just for > > > if x < 0 then > > > return floor(x+1) > > > else > > > return floor(x) > > > end if > > This is not quite correct. if x is say, -2, it will return -1 rather than > > the > > correct -2. > > This will work: > > if integer(x) then > > return x > > elsif x<0 then > > return floor(x+1) > > else > > return floor(x) > > end if > A simpler method that works is: > if x < 0 then > return -floor(-x) > else > return floor(x) > end if Nice job, you guys. Thanks! :)