sine and cosine

BlitzMax Forums/BlitzMax Beginners Area/sine and cosine

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Actually for the test to be (more) fair, sin and cos takes a floating point parameter while an array takes an integer. Therefore the values passed to them should be in the right format to avoid converting from float to int or vice versa.
Local pcos#[360]
Local psin#[360]

For x = 0 To 359
	pcos[x] = Cos(x)
	psin[x] = Sin(x)
Next

sec = MilliSecs()
For x = 0 To 60000
 	n# = pcos[Rand(0,359)]/psin[Rand(0,359)]*pcos[Rand(0,359)]/psin[Rand(0,359)]+pcos[Rand(0,359)]/psin[Rand(0,359)]/pcos[Rand(0,359)]/psin[Rand(0,359)]
Next
lapse = MilliSecs() - sec 
Print lapse	

sec = MilliSecs()
For x = 0 To 60000
	n# = Cos(Rnd(0.0,359.0))/Sin(Rnd(0.0,359.0))*Cos(Rnd(0.0,359.0))/Sin(Rnd(0.0,359.0))+Cos(Rnd(0.0,359.0))/Sin(Rnd(0.0,359.0))/Cos(Rnd(0.0,359.0))/Sin(Rnd(0.0,359.0))
Next
lapse = MilliSecs()-sec
Print lapse
This on average gives 77ms vs. 97ms on my laptop. But if you have something that takes less than 100 millisecs to do 480008 calculations/lookups, there is absolutely no point in optimizing, unless you will be using it excessively. Especially when you consider that you've effectively lost a lot of precision by using a lookup.