Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

math.pow alternative in Lua?

Tags:

lua

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?

like image 485
Zack Lee Avatar asked Apr 17 '26 18:04

Zack Lee


1 Answers

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.6).

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.)

like image 96
Keith Thompson Avatar answered Apr 20 '26 12:04

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!