math.pow alternative in Lua?

lua
10,696

Lua has no math.pow() function.

Correction: Lua's math.pow() function is deprecated as of release 5.3, as documented here. But it still exists in the latest release (up to and including 5.4.0-work2).

If you're getting a syntax error, it's due to some other problem. Please update your question to show us the exact code that produces the error, as well as the error message.

In any case, you should use the built-in ^ exponentiation operator rather than the math.pow() function.

(Unlike C and some other languages, Lua uses ~ as the bitwise xor operator.)

Share:
10,696
Zack Lee
Author by

Zack Lee

Updated on June 04, 2022

Comments

  • Zack Lee
    Zack Lee almost 2 years

    I cannot use math.pow(x,y) in Lua.

    I don't know why, it says syntax error.

    math.sin(f) and math.cos(f) works however.

    Is there other alternative for math.pow() in Lua?

    • Keith Thompson
      Keith Thompson over 5 years
      I've updated my answer. math.pow() is deprecated, but it still exists. It shouldn't cause a syntax error. Please update your question to show the exact code that produces the error, as well as the text of the error message. You almost certainly made some other error.
    • Kokizzu
      Kokizzu about 2 years
      still can if you are using LuaJIT 2.1.0-beta3