Search code examples
functionluadecimalsign

Lua decimal sign?


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?


Solution

  • You can check for the sign like this:

    i = -2
    if i == math.abs(i) then -- or i >= 0
       print "positive"
    else
       print "negative"
    end