It looks like you're new here. If you want to get involved, click one of these buttons!

- 6.9K All Categories
- 3.9K General questions
- 93 Roadmap
- 296 Game & application design
- 278 Plugins
- 60 User experience
- 68 Marketplace
- 249 Code snippets
- 33 Building a team?
- 236 Suggestions & requests
- 328 Announce your apps made with Gideros.
- 82 Step by step tutorials
- 570 Bugs and issues
- 165 Introduce yourself
- 172 Announcements
- 73 Forum talk
- 367 Relax cafe

plamen
Member

hey guys, any idea about what math optimization are in Lua. How much expensive are trigonometric functions and are there FPU acceleration of ARM compilation for LUA math functions? In other words i know for normal platforms Lua math lib uses co-processor accelerations but what about ARM in mobiles? It will flip all the game math for me if i have to swap math.atan2 and math.sqrt with some silly tables.

Tagged:

## Comments

http://www.lua.org/source/5.2/lmathlib.c.html

@GregBUG stated that "i used to test to see if lua math.sin / math.cos was slower than (look-up table) sin/cos table."

and the result:

"math.sin and math.cos are much more faster!"

See pages 17 and 18. http://www.lua.org/gems/sample.pdf

i compared four versions with the code below and the results are the following:

given an integer degree to compute its sine with localizing and lookup table you can do it 2.5 times faster than by simply using the math functions. so at least these tests seem to contradict the statement of "math.sin and math.cos are much more faster!". of course if you have the angle in rad then the gain is less, but it is still significant.

in any case i never thought about localizing previously, i got this idea from @Javi 's link, and it is a very useful trick as well, maybe more important then using a lookup table.

Fragmenter - animated loop machine and IKONOMIKON - the memory game

test code run faster using sin/cos func than lookup table.... (on desktop run faster lookup table btw)

i also I agree with @keszegh that localizing and optimizations (like suggested by @javi) maybe more important that using a lookup table.

www.tntengine.com

the results in the same order running on my tegra2 tablet:

v1 8.1

v2 9.6

v3 7.2

v4 10.1

so indeed localizing seems to be the most efficient thing. on the tablet the lookup table slows down the process when localizing but it is still a bit faster then doing no tricks at all.

Fragmenter - animated loop machine and IKONOMIKON - the memory game