Search code examples
lua

Is there any ways to use math.pow in lua 5.3?


I have found an article about this, now I have discovered a syntax error for this really useful built-in function. My code is simple but the error isn't:

print(math.pow(10, 2))

Error: File:2: attempt to call a nil value (field 'pow')

If math.pow no longer exist in Lua 5.3, maybe I have to create a new function for real. Still, I want to be a lazy donkey :)


Solution

  • math.pow was replaced by the ^ operator: 10 ^ 2.

    If you have many calls to math.pow, you can simply add the function:

    math = math or {}
    function math.pow(a, b)
        return a ^ b
    end