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.

P#14682 2015-09-27 18:41 ( Edited 2015-10-15 19:40)

flr(x)+1

P#14683 2015-09-27 19:19 ( Edited 2015-09-27 23:19)

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)
:: Rhys

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

P#14685 2015-09-27 19:55 ( Edited 2015-09-27 23:55)

-flr(-x)

P#14686 2015-09-27 21:38 ( Edited 2015-09-28 01:38)

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

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

EDIT: what eruonna said!

P#14687 2015-09-27 21:39 ( Edited 2015-09-28 01:41)

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

P#14692 2015-09-27 22:53 ( Edited 2015-09-28 02:53)
:: matt

@eruonna my chosen solution also!

P#14701 2015-09-28 05:46 ( Edited 2015-09-28 09:46)

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

P#15386 2015-10-14 22:34 ( Edited 2015-10-15 02:34)

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)

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

P#15401 2015-10-15 15:40 ( Edited 2015-10-15 19:40)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2019-12-11 22:59 | 0.018s | 2097k | Q:32