complex asin with <complex> (NOT complex.h)

Hey there,

as we all may know the <complex> and the <complex.h> are decoupled and one shouldn't use the .h in a c++ program. BUT i have a real issue with that:

the <complex.h> allows me to calculate a complex asin (via casin),
the <complex> simply doesn't!
The only "workaround" i found was a boostc++ library (http://www.boost.org/doc/libs/1_42_0/boost/math/complex/asin.hpp)

The C Code that works is:
double complex c_snellius_beta(double alpha_r, double alpha_im, double n_in, double k_in, double n_out, double k_out){
double complex c_alpha, N_in, N_out;
c_alpha = alpha_r + I*alpha_im;
N_in = n_in + I*k_in;
N_out = n_out + I*k_out;
return casin(N_in*csin(c_alpha)/N_out);
}


And my C++ Code is:
complex<double> snellius_beta(double alpha_real, double alpha_imag, double n_in, double k_in, double n_out, double k_out){
complex<double> alpha(alpha_real,alpha_imag), N_in(n_in,k_in), N_out(n_out,k_out);
return sin(N_in*sin(alpha)/N_out); //but it has to calc arcsin!!!!!
}


That really limits me and it's my first real disappointment with Cpp compared to that old C99 lib - any suggestions?
complex.h was introduced in C99, and the current C++ standard is C++98. Unless you were hoping for the C++ committee to be composed mainly of clairvoyants, this is to be expected.

I'm unfamiliar with complex trigonometric functions, but surely you can still do the calculation yourself by stringing together several math functions.
There are a number of ways to solve for inverse trigonometric functions.
Standard functions extrapolate from a table. You could do the same.
Other solutions can be found here:
http://en.wikipedia.org/wiki/Inverse_trigonometric_functions

Probably the simplest for you to implement will be from the half-angle formula, found about a quarter of the way down the Wikipedia page:

1
2
3
4
complex arcsin( const complex& x )
  {
  return 2 * arctan( x / (1 + sqrt( 1 - (x * x) )) );
  }

You may also want to peruse the logarithmic forms near the bottom of the page.

Good luck!
Thanks!
That's how I solved it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Implement complex arcsin
complex<double> cmplxasin(complex<double> z){
	complex<double> casin;
	for(int n=0; n<=25; n++){
		long fac2n = 1;
		for (int i = 2; i <= 2*n; i++){
			fac2n *= i; 
		}
		long facn = 1;
		for (int j = 2; j <= n; j++){
			facn *= j; 
		}
		complex<double> fac2N(fac2n,0), facN(facn,0), czwei(2,0), czweiN(2*n,0),czweiN1(2*n+1,0);
		casin += (fac2N/(pow(czwei,czweiN)*pow(facN,czwei)))*pow(z,czweiN1)/(czweiN1);
	}
	return casin;
}


Thank you :)
Topic archived. No new replies allowed.