This is what range_lerp should be doing.
You pass it the value you want to modify, the range of values it can currently travel between and the new range of values you want it to travel between.
So my idea is you have a sin value currently fluctuating between -1 and 1. The range_lerp above should (not tested) convert :
-1 to 0 into -45 to 0
0 to 1 into 0 to 45
You then just set the rotation to this value every frame. As long as 'sin(sweeping)' is fluctuating between -1 and 1 correctly that should work.
Anyway may be better off posting in the Programming category in the forum.