Log In  


A rounding-up function doesn't seem to exist for some reason? I tend to use stuff like that for damages, to round to the player, and monster's, favour. I might not have dug far enough, but I couldn't find any built in thing like that.

3


flr(x)+1


And similarly, if you need a traditional round() function, flr(x+0.5).


Keep in mind that ceil(1) is meant to be 1.


-flr(-x)


I think... FLR(x+1-SHR(1,16)) might be the desired thing.

or FLR(x+BNOT(0xFFFF)) fewer tokenzzzzzzz

EDIT: what eruonna said!


Oh, I like -flr(-x). Seems to have the least amount of tokens without putting it in the base library.


@eruonna my chosen solution also!


Is there a reason we should not like a real ceil() function to be added ?


Chose whatever you want for brevity/token saving.

Keep in mind, some of the suggested ceil's don't work correctly in some cases.

function ceil1(x)
  return -flr(-x)
end

function ceil2(x)
  return flr(x+0.999999999)
end

function ceil3(x)
  return flr(x+1-shr(1,16))
end

function ceil4(x)
  return flr(x)+1
end

tests = {ceil1,ceil2,ceil3,ceil4}

function a(t,s)
  if not t then print(s) end
end

for ic,ceil in pairs(tests) do
  a(ceil(0) == 0,
    'c'..ic..":fail zero")
  a(ceil(1.5) == 2,
    'c'..ic..":fail frac")
  a(ceil(-1) == -1,
   'c'..ic..":fail neg")
  a(ceil(-1.5) == -1,
    'c'..ic..":faiil neg frac")
  a(ceil(0.0001)==1,
    'c'..ic..":fail precision")
end

IMO all types of rounds should be in standard library, so you can concentrate on making actual game. Token limit is bad as it is, no reason to make it even worse by having to rewrite general-use fucntions that are useful or might be useful in almost every game.


Thanks for the cheatsheet, that'll be useful until/if this gets integrated.



[Please log in to post a comment]