Lua decimal sign?

SilentCipher picture SilentCipher · Aug 23, 2009 · Viewed 10.4k times · Source

I've used this in other languages, but lua seems to be lacking this rather useful function.

Could one of you nice chappies provide me a lua function to get the sign of the number passed to it?

Answer

lhf picture lhf · Aug 23, 2009
function math.sign(x)
   if x<0 then
     return -1
   elseif x>0 then
     return 1
   else
     return 0
   end
end