Andrew Spott
Andrew Spott

Reputation: 3637

Exponentiation of a large floating point imaginary argument

How do I go about calculating exp(i * x) where |x| >> 2 pi?

I know that it can be done with an arbitrary precision library, but is there an algorithm to do it stably (without roundoff errors) that doesn't require a library?

Upvotes: 0

Views: 107

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224310

exp(i*x) is cos(x) + i*sin(x). A good math library will calculate cos(x) and sin(x) correctly even when x is large. E.g., you should get correct results with the OS X or iOS standard math library, within a few ULP.

In C, this should work:

#include <complex.h>
…
    double complex Y = cexp(I * x);

Upvotes: 4

Related Questions