Cos/sin or precalculated

BlitzMax Forums/BlitzMax Beginners Area/Cos/sin or precalculated

tonyg(Posted 2005) [#1]
It appears the cos/sin commands are as quick as a precalculated lookup table.
Can anybody verify this?


FlameDuck(Posted 2005) [#2]
No. It depends on where the bottleneck is. Typically Cos/Sin instructions will be faster, because they do not nessecarilly access memory, thus using the FPU will be faster (because it's on a faster bus) than accessing memory.

In theory.


Warren(Posted 2005) [#3]
And we've been over this before, but ... if sin/cos is your bottleneck, you're done. Ship it.


tonyg(Posted 2005) [#4]
I've always precalculated by habit. While the difference in B2D/B3D was noticeable on older cpus (admittedly for a large number of calls) I agree it's marginal on quicker machines.
In Bmx both precalculated and sin/cos seem remarkably fast.
If you code for less powerful machines you might want to give the sin/cos another try and see what you think.


ImaginaryHuman(Posted 2005) [#5]
I would definitely consider using the functions directly given the way modern fast CPU's work. I was quite surprised to write a object-bouncing-around-screen routine that seemed to zip right along regardless of calling Sin and Cos several hundred times per frame. I don't think it's a problem. And really, for most computation, modern CPU's are very fast and you should have plenty of time even if Cos/Sin are a little slow.


Robert(Posted 2005) [#6]
Sin / Cos are probably two of the most used mathematical functions for any gaming application. I believe that BlitzMAX simply uses the sin / cos functions that ship with GCC, which are going to be very well optimised. Hence these functions should be very fast.