I should create a program which computes the cosines and sines of a sequence of angles k*α, where k is a growing natural number (i.e., 0, 1, 2,…) and α is a constant angle which lies between 0 and π. I would like to make this program as fast as possibile.
Hence, I want to compute first the cosine of each angle, and then the related sine with sqrt(1-cos(k*α)^2). The problem is the sign of the sine, which should be determined by the position of the angle k*α on the real line.
I would like to know how I could implement this dynamic comparison as fast as possibile, or if the fastest way to proceed is to compute directly the sine, too.
After some time, I thought again about this problem and I found a really simple solution:
Problem solved. 🙂