20#ifndef CCGSL_COMPLEX_HPP
21#define CCGSL_COMPLEX_HPP
26#include<gsl/gsl_complex.h>
27#include<gsl/gsl_complex_math.h>
58 memcpy( this->dat, dat, 2 *
sizeof(
double ) );
66 GSL_SET_REAL(
this,
real );
67 GSL_SET_IMAG(
this,
imag );
74 GSL_SET_REAL(
this, std::real( z ) );
75 GSL_SET_IMAG(
this, std::imag( z ) );
85 GSL_SET_REAL(
this, GSL_REAL( z ) );
86 GSL_SET_IMAG(
this, GSL_IMAG( z ) );
92#ifdef __GXX_EXPERIMENTAL_CXX0X__
93 explicit operator std::complex<double>()
const {
94 return std::complex<double>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
97 operator std::complex<double>()
const {
98 std::complex<double> z = std::complex<double>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
106 gsl_complex&
get(){
return dynamic_cast<gsl_complex&
>( *this ); }
111 gsl_complex
const&
get()
const {
return dynamic_cast<gsl_complex const&
>( *this ); }
126 GSL_SET_COMPLEX( &z, r *
std::cos( theta ), r *
std::sin( theta ) );
return z; }
132 void set_complex(
double x,
double y ){ GSL_SET_COMPLEX(
this, x, y );}
137 double real()
const {
return GSL_REAL( *
this ); }
142 double imag()
const {
return GSL_IMAG( *
this ); }
147 void set_real(
double x ){ GSL_SET_REAL(
this, x ); }
152 void set_imag(
double y ){ GSL_SET_IMAG(
this, y ); }
158 static double arg(
complex const& z ){
return gsl_complex_arg( z ); }
164 static double abs(
complex const& z ){
return gsl_complex_abs( z ); }
170 static double abs2(
complex const& z ){
return gsl_complex_abs2( z ); }
184 {
return complex( gsl_complex_add(
a,
b ) ); }
192 {
return complex( gsl_complex_sub(
a,
b ) ); }
200 {
return complex( gsl_complex_mul(
a,
b ) ); }
208 {
return complex( gsl_complex_div(
a,
b ) ); }
216 {
return complex( gsl_complex_add_real(
a, x ) ); }
224 {
return complex( gsl_complex_sub_real(
a, x ) ); }
232 {
return complex( gsl_complex_mul_real(
a, x ) ); }
240 {
return complex( gsl_complex_div_real(
a, x ) ); }
248 {
return complex( gsl_complex_add_imag(
a, y ) ); }
256 {
return complex( gsl_complex_sub_imag(
a, y ) ); }
264 {
return complex( gsl_complex_mul_imag(
a, y ) ); }
272 {
return complex( gsl_complex_div_imag(
a, y ) ); }
279 {
return complex( gsl_complex_conjugate( z ) ); }
286 {
return complex( gsl_complex_inverse(
a ) ); }
293 {
return complex( gsl_complex_negative(
a ) ); }
300 {
return complex( gsl_complex_sqrt( z ) ); }
307 {
return complex( gsl_complex_sqrt_real( x ) ); }
315 {
return complex( gsl_complex_pow(
a,
b ) ); }
323 {
return complex( gsl_complex_pow_real(
a,
b ) ); }
330 {
return complex( gsl_complex_exp(
a ) ); }
337 {
return complex( gsl_complex_log(
a ) ); }
344 {
return complex( gsl_complex_log10(
a ) ); }
352 {
return complex( gsl_complex_log_b(
a,
b ) ); }
359 {
return complex( gsl_complex_sin(
a ) ); }
366 {
return complex( gsl_complex_cos(
a ) ); }
373 {
return complex( gsl_complex_sec(
a ) ); }
380 {
return complex( gsl_complex_csc(
a ) ); }
387 {
return complex( gsl_complex_tan(
a ) ); }
394 {
return complex( gsl_complex_cot(
a ) ); }
401 {
return complex( gsl_complex_arcsin(
a ) ); }
408 {
return complex( gsl_complex_arcsin_real(
a ) ); }
415 {
return complex( gsl_complex_arccos(
a ) ); }
422 {
return complex( gsl_complex_arccos_real(
a ) ); }
429 {
return complex( gsl_complex_arcsec(
a ) ); }
436 {
return complex( gsl_complex_arcsec_real(
a ) ); }
443 {
return complex( gsl_complex_arccsc(
a ) ); }
450 {
return complex( gsl_complex_arccsc_real(
a ) ); }
457 {
return complex( gsl_complex_arctan(
a ) ); }
464 {
return complex( gsl_complex_arccot(
a ) ); }
471 {
return complex( gsl_complex_sinh(
a ) ); }
478 {
return complex( gsl_complex_cosh(
a ) ); }
485 {
return complex( gsl_complex_sech(
a ) ); }
492 {
return complex( gsl_complex_csch(
a ) ); }
499 {
return complex( gsl_complex_tanh(
a ) ); }
506 {
return complex( gsl_complex_coth(
a ) ); }
513 {
return complex( gsl_complex_arcsinh(
a ) ); }
520 {
return complex( gsl_complex_arccosh(
a ) ); }
527 {
return complex( gsl_complex_arccosh_real(
a ) ); }
534 {
return complex( gsl_complex_arcsech(
a ) ); }
541 {
return complex( gsl_complex_arccsch(
a ) ); }
548 {
return complex( gsl_complex_arctanh(
a ) ); }
555 {
return complex( gsl_complex_arctanh_real(
a ) ); }
562 {
return complex( gsl_complex_arccoth(
a ) ); }
584 return dat[0] < z.dat[0] or (dat[0] == z.dat[0] and dat[1] < z.dat[1]); }
592 return dat[0] > z.dat[0] or (dat[0] == z.dat[0] and dat[1] > z.dat[1]); }
630 operator gsl_complex()
const {
631 gsl_complex z; memcpy( z.dat,
dat, 2 *
sizeof(
double ) );
return z; }
638 complex z; memcpy( z.dat,
dat, 2 *
sizeof(
double ) );
return z; }
657 memcpy(
dat, z.dat, 2 *
sizeof(
double ) );
return *
this; }
664 void set_complex(
double x,
double y ){ GSL_SET_COMPLEX(
this, x, y );}
669 double real()
const {
return GSL_REAL( *
this ); }
674 double imag()
const {
return GSL_IMAG( *
this ); }
679 void set_real(
double x ){ GSL_SET_REAL(
this, x ); }
684 void set_imag(
double y ){ GSL_SET_IMAG(
this, y ); }
733 template<
typename Ch,
typename Tr>
734 std::basic_ostream<Ch,Tr>&
operator<<( std::basic_ostream<Ch,Tr>& stream, complex
const& z ){
736 if( i >= 0 ) stream << z.real() <<
"+" << i <<
"i";
737 else stream << z.real() <<
"-" << -i <<
"i";
753 template<
typename Ch,
typename Tr>
754 std::basic_ostream<Ch,Tr>&
operator<<( std::basic_ostream<Ch,Tr>& stream,
755 complex_ref
const& z ){
757 if( i >= 0 ) stream << z.real() <<
"+" << i <<
"i";
758 else stream << z.real() <<
"-" << -i <<
"i";
This class can be used like a pointer for complex objects so that we can iterate over a vector (for e...
complex_ref const operator*() const
Dereference the pointer.
complex_ref * operator->()
Dereference the pointer.
complex_ref operator*()
Dereference the pointer.
complex_ref const * operator->() const
Dereference the pointer.
complex_ptr(double *dat)
Typically we are given a pointer to the data storing the complex and need to construct a complex_ptr ...
This class can be used like a reference for complex objects so that we can iterate over a vector (for...
void set_imag(double y)
C++ version of GSL_SET_IMAG().
double real() const
C++ version of GSL_REAL().
complex_ref(double *dat)
We use this in constructing complex_ptr objects.
void set_complex(double x, double y)
C++ version of GSL_SET_COMPLEX().
complex_ref & operator=(complex const &z)
Assignment from complex.
double imag() const
C++ version of GSL_IMAG().
void set_real(double x)
C++ version of GSL_SET_REAL().
complex_ref()
The default constructor is only really useful for assigning to.
complex_ref(complex &z)
Make sure we can construct from a complex.
This class handles complex numbers.
static complex log10(complex const &a)
C++ version of gsl_complex_log10().
static complex arcsec_real(double a)
C++ version of gsl_complex_arcsec_real().
static complex arcsec(complex const &a)
C++ version of gsl_complex_arcsec().
static complex arccsc_real(double a)
C++ version of gsl_complex_arccsc_real().
static double logabs(complex const &z)
C++ version of gsl_complex_logabs().
complex(double *dat)
Allow construction from raw data.
static complex sqrt(complex const &z)
C++ version of gsl_complex_sqrt().
static complex log_b(complex const &a, complex const &b)
C++ version of gsl_complex_log_b().
static complex add_real(complex const &a, double x)
C++ version of gsl_complex_add_real().
static complex arctanh(complex const &a)
C++ version of gsl_complex_arctanh().
static complex arccsc(complex const &a)
C++ version of gsl_complex_arccsc().
bool operator==(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
bool operator>(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
static complex div(complex const &a, complex const &b)
C++ version of gsl_complex_div().
static complex arccot(complex const &a)
C++ version of gsl_complex_arccot().
static complex tan(complex const &a)
C++ version of gsl_complex_tan().
bool operator>=(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
static complex mul_real(complex const &a, double x)
C++ version of gsl_complex_mul_real().
bool operator!=(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
static complex sub_real(complex const &a, double x)
C++ version of gsl_complex_sub_real().
static complex inverse(complex const &a)
C++ version of gsl_complex_inverse().
bool operator<=(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
static complex sec(complex const &a)
C++ version of gsl_complex_sec().
static complex add(complex const &a, complex const &b)
C++ version of gsl_complex_add().
static complex sin(complex const &a)
C++ version of gsl_complex_sin().
double imag() const
C++ version of GSL_IMAG().
static double abs2(complex const &z)
C++ version of gsl_complex_abs2().
static complex tanh(complex const &a)
C++ version of gsl_complex_tanh().
static complex arcsinh(complex const &a)
C++ version of gsl_complex_arcsinh().
static complex sub_imag(complex const &a, double y)
C++ version of gsl_complex_sub_imag().
static complex arctan(complex const &a)
C++ version of gsl_complex_arctan().
static complex arccos_real(double a)
C++ version of gsl_complex_arccos_real().
static complex arccoth(complex const &a)
C++ version of gsl_complex_arccoth().
static complex polar(double r, double theta)
C++ version of gsl_complex_rect().
static complex div_real(complex const &a, double x)
C++ version of gsl_complex_div_real().
static complex arccsch(complex const &a)
C++ version of gsl_complex_arccsch().
static complex arccosh_real(double a)
C++ version of gsl_complex_arccosh_real().
static complex csc(complex const &a)
C++ version of gsl_complex_csc().
void set_complex(double x, double y)
C++ version of GSL_SET_COMPLEX().
static complex sech(complex const &a)
C++ version of gsl_complex_sech().
complex(gsl_complex const &z)
Constructor from base class.
static complex cos(complex const &a)
C++ version of gsl_complex_cos().
static double arg(complex const &z)
C++ version of gsl_complex_arg().
void set_real(double x)
C++ version of GSL_SET_REAL().
static complex mul_imag(complex const &a, double y)
C++ version of gsl_complex_mul_imag().
static complex coth(complex const &a)
C++ version of gsl_complex_coth().
static complex negative(complex const &a)
C++ version of gsl_complex_negative().
static complex arctanh_real(double a)
C++ version of gsl_complex_arctanh_real().
static complex csch(complex const &a)
C++ version of gsl_complex_csch().
static complex exp(complex const &a)
C++ version of gsl_complex_exp().
static complex pow_real(complex const &a, double b)
C++ version of gsl_complex_pow_real().
static complex conjugate(complex const &z)
C++ version of gsl_complex_conjugate().
static complex sub(complex const &a, complex const &b)
C++ version of gsl_complex_sub().
void set_imag(double y)
C++ version of GSL_SET_IMAG().
static complex sqrt_real(double x)
C++ version of gsl_complex_sqrt_real().
static complex arccosh(complex const &a)
C++ version of gsl_complex_arccosh().
static complex sinh(complex const &a)
C++ version of gsl_complex_sinh().
double real() const
C++ version of GSL_REAL().
static complex mul(complex const &a, complex const &b)
C++ version of gsl_complex_mul().
static complex rect(double x, double y)
C++ version of gsl_complex_rect().
complex(std::complex< double > const &z)
Allow construction from a std::complex<double>.
gsl_complex const & get() const
Get the base class object.
static complex cosh(complex const &a)
C++ version of gsl_complex_cosh().
static complex div_imag(complex const &a, double y)
C++ version of gsl_complex_div_imag().
static complex log(complex const &a)
C++ version of gsl_complex_log().
complex(double const real, double const imag)
Allow construction from real and imaginary values.
bool operator<(complex const &z) const
A complex object must be less than comparable so that it can be used as a container value type.
static complex pow(complex const &a, complex const &b)
C++ version of gsl_complex_pow().
gsl_complex & get()
Get the base class object.
static complex arcsech(complex const &a)
C++ version of gsl_complex_arcsech().
static complex arcsin(complex const &a)
C++ version of gsl_complex_arcsin().
static complex arcsin_real(double a)
C++ version of gsl_complex_arcsin_real().
static complex cot(complex const &a)
C++ version of gsl_complex_cot().
complex()
The default constructor is only really useful for assigning to.
static double abs(complex const &z)
C++ version of gsl_complex_abs().
static complex arccos(complex const &a)
C++ version of gsl_complex_arccos().
static complex add_imag(complex const &a, double y)
C++ version of gsl_complex_add_imag().
This class handles matrix_complex objects as shared handles.
This class handles vector_complex objects as shared handles.
complex log(complex const &a)
C++ version of gsl_complex_log().
complex sqrt_real(double x)
C++ version of gsl_complex_sqrt_real().
double arg(complex const &z)
C++ version of gsl_complex_arg().
complex pow(complex const &a, complex const &b)
C++ version of gsl_complex_pow().
complex polar(double r, double theta)
C++ version of gsl_complex_rect().
complex conjugate(complex const &z)
C++ version of gsl_complex_conjugate().
complex arcsec(complex const &a)
C++ version of gsl_complex_arcsec().
complex coth(complex const &a)
C++ version of gsl_complex_coth().
complex arcsin(complex const &a)
C++ version of gsl_complex_arcsin().
complex div(complex const &a, complex const &b)
C++ version of gsl_complex_div().
double abs2(complex const &z)
C++ version of gsl_complex_abs2().
complex csc(complex const &a)
C++ version of gsl_complex_csc().
complex cos(complex const &a)
C++ version of gsl_complex_cos().
complex arctanh(complex const &a)
C++ version of gsl_complex_arctanh().
complex arcsech(complex const &a)
C++ version of gsl_complex_arcsech().
complex arccos(complex const &a)
C++ version of gsl_complex_arccos().
complex exp(complex const &a)
C++ version of gsl_complex_exp().
complex inverse(complex const &a)
C++ version of gsl_complex_inverse().
complex arccsch(complex const &a)
C++ version of gsl_complex_arccsch().
complex cosh(complex const &a)
C++ version of gsl_complex_cosh().
complex arccos_real(double a)
C++ version of gsl_complex_arccos_real().
complex sin(complex const &a)
C++ version of gsl_complex_sin().
complex negative(complex const &a)
C++ version of gsl_complex_negative().
complex sub(complex const &a, complex const &b)
C++ version of gsl_complex_sub().
complex sub_imag(complex const &a, double y)
C++ version of gsl_complex_sub_imag().
complex sqrt(complex const &z)
C++ version of gsl_complex_sqrt().
complex sub_real(complex const &a, double x)
C++ version of gsl_complex_sub_real().
complex arctanh_real(double a)
C++ version of gsl_complex_arctanh_real().
complex sec(complex const &a)
C++ version of gsl_complex_sec().
complex sech(complex const &a)
C++ version of gsl_complex_sech().
complex arcsec_real(double a)
C++ version of gsl_complex_arcsec_real().
complex cot(complex const &a)
C++ version of gsl_complex_cot().
double abs(complex const &z)
C++ version of gsl_complex_abs().
complex arctan(complex const &a)
C++ version of gsl_complex_arctan().
complex log_b(complex const &a, complex const &b)
C++ version of gsl_complex_log_b().
complex mul(complex const &a, complex const &b)
C++ version of gsl_complex_mul().
complex div_real(complex const &a, double x)
C++ version of gsl_complex_div_real().
complex mul_real(complex const &a, double x)
C++ version of gsl_complex_mul_real().
complex add_imag(complex const &a, double y)
C++ version of gsl_complex_add_imag().
complex arccsc(complex const &a)
C++ version of gsl_complex_arccsc().
complex arccot(complex const &a)
C++ version of gsl_complex_arccot().
complex pow_real(complex const &a, double b)
C++ version of gsl_complex_pow_real().
complex sinh(complex const &a)
C++ version of gsl_complex_sinh().
complex arcsin_real(double a)
C++ version of gsl_complex_arcsin_real().
complex tan(complex const &a)
C++ version of gsl_complex_tan().
complex tanh(complex const &a)
C++ version of gsl_complex_tanh().
complex rect(double x, double y)
C++ version of gsl_complex_rect().
complex arccoth(complex const &a)
C++ version of gsl_complex_arccoth().
double logabs(complex const &z)
C++ version of gsl_complex_logabs().
complex log10(complex const &a)
C++ version of gsl_complex_log10().
complex arcsinh(complex const &a)
C++ version of gsl_complex_arcsinh().
complex arccosh_real(double a)
C++ version of gsl_complex_arccosh_real().
complex arccosh(complex const &a)
C++ version of gsl_complex_arccosh().
complex add(complex const &a, complex const &b)
C++ version of gsl_complex_add().
complex mul_imag(complex const &a, double y)
C++ version of gsl_complex_mul_imag().
complex csch(complex const &a)
C++ version of gsl_complex_csch().
complex arccsc_real(double a)
C++ version of gsl_complex_arccsc_real().
complex div_imag(complex const &a, double y)
C++ version of gsl_complex_div_imag().
complex add_real(complex const &a, double x)
C++ version of gsl_complex_add_real().
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
double a(int order, double qq)
C++ version of gsl_sf_mathieu_a().
The gsl package creates an interface to the GNU Scientific Library for C++.
gsl_const_complex_packed_array complex_const_packed_array
Typedef.
gsl_const_complex_packed_ptr complex_const_packed_ptr
Typedef.
gsl_complex_packed_array complex_packed_array
Typedef.
gsl_complex_packed complex_packed
Typedef.
gsl_const_complex_packed complex_const_packed
Typedef.
gsl_complex_packed_ptr complex_packed_ptr
Typedef.
std::basic_ostream< Ch, Tr > & operator<<(std::basic_ostream< Ch, Tr > &stream, complex const &z)
Define the << operator so that we can use expressions like.