on-internet
← Community

How do I calculate $2^n$th roots of unity accurately?

Stack Overflow ·

I'm trying to get all the (2^n)th roots of unity in order, accurately and quickly. The obvious solution (calculating the roots as exp((2pi i k)/2^n)) is too inaccurate; floating point tells me that exp(i pi)=-1+0.00000000000000012246467991473532i. I know about the IEEE 754 recommended functions cosPi and sinPi, which would solve my problem, but they're not available on my system. I'd like a fast solution, so high precision math is out of the question. I'm not that concerned with accuracy, but this is simply unacceptable. I checked, and it's 4.37e18 ulps off of the correct answer.

Comments

Sign in or sign up to comment and upvote.

No comments yet.