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.
P#14682 2015-09-27 18:41 ( Edited 2015-10-15 19:40)


And similarly, if you need a traditional round() function, flr(x+0.5).
P#14684 2015-09-27 19:27 ( Edited 2015-09-27 23:27)


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 |

P#15389 2015-10-15 06:41 ( Edited 2015-10-15 10:41)


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.
P#15394 2015-10-15 09:39 ( Edited 2015-10-15 13:39)
[Please log in to post a comment]