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?
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);