Optimising Challenge

BlitzMax Forums/BlitzMax Programming/Optimising Challenge

Hi all,
I got this interpolation code from code archives from Freborg and I need to speed it up (see Tween360 below).

It is used to tween the last rotation to the next rotation, however it is too slow for the number of items I want to use it for. Thing is, I believe this routine is overkill for just tweening between angles...

All I want to do is tween between two angles, for example a = 350 and b= 10 using 0..1 as the time so I can get any tweened position between them... As you might have thought, it will actually spin the other way with normal tweening like this:

Fast but doesn't account for 360 degrees:
Function Tween:Float(p1:Float,p2:Float,t:Float)
	Return p1 + t * (p2 - p1)
End Function
But the following routine is too slow, so any ideas how I can get a tween for angles that works like the above but with the reliability of the routine below? I suspect I don't actually need all those cosines and atan2!

Slow but works:
Function Tween360:Float( a:Float , b:Float , time:Float )
	Local ix:Float = Sin(a)
	Local iy:Float = Cos(a)
	Local jx:Float = Sin(b)
	Local jy:Float = Cos(b)
	Return ATan2(ix-(ix-jx)*time,iy-(iy-jy)*time)
End Function