Cos/sin or precalculated
BlitzMax Forums/BlitzMax Beginners Area/Cos/sin or precalculated| 
 | ||
| It appears the cos/sin commands are as quick as a precalculated lookup table. Can anybody verify this? | 
| 
 | ||
| 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. | 
| 
 | ||
| And we've been over this before, but ... if sin/cos is your bottleneck, you're done.  Ship it. | 
| 
 | ||
| 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. | 
| 
 | ||
| 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. | 
| 
 | ||
| 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. |