20#ifndef CCGSL_COMPLEX_LONG_DOUBLE_HPP
21#define CCGSL_COMPLEX_LONG_DOUBLE_HPP
26#include<gsl/gsl_complex.h>
27#include<gsl/gsl_complex_math.h>
58 memcpy( this->dat, dat, 2 *
sizeof(
long 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<long double>()
const {
94 return std::complex<long double>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
97 operator std::complex<long double>()
const {
98 std::complex<long double> z = std::complex<long double>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
106 gsl_complex_long_double&
get(){
return dynamic_cast<gsl_complex_long_double&
>( *this ); }
111 gsl_complex_long_double
const&
get()
const {
return dynamic_cast<gsl_complex_long_double const&
>( *this ); }
126 GSL_SET_COMPLEX( &z, r *
std::cos( theta ), r *
std::sin( theta ) );
return z; }
137 long double real()
const {
return GSL_REAL( *
this ); }
142 long double imag()
const {
return GSL_IMAG( *
this ); }
147 void set_real(
long double x ){ GSL_SET_REAL(
this, x ); }
152 void set_imag(
long double y ){ GSL_SET_IMAG(
this, y ); }
174 return dat[0] < z.dat[0] or (dat[0] == z.dat[0] and dat[1] < z.dat[1]); }
182 return dat[0] > z.dat[0] or (dat[0] == z.dat[0] and dat[1] > z.dat[1]); }
220 operator gsl_complex_long_double()
const {
221 gsl_complex_long_double z; memcpy( z.dat,
dat, 2 *
sizeof(
long double ) );
return z; }
247 memcpy(
dat, z.dat, 2 *
sizeof(
long double ) );
return *
this; }
259 long double real()
const {
return GSL_REAL( *
this ); }
264 long double imag()
const {
return GSL_IMAG( *
this ); }
269 void set_real(
long double x ){ GSL_SET_REAL(
this, x ); }
274 void set_imag(
long double y ){ GSL_SET_IMAG(
this, y ); }
323 template<
typename Ch,
typename Tr>
324 std::basic_ostream<Ch,Tr>&
operator<<( std::basic_ostream<Ch,Tr>& stream, complex_long_double
const& z ){
325 long double i = z.imag();
326 if( i >= 0 ) stream << z.real() <<
"+" << i <<
"i";
327 else stream << z.real() <<
"-" << -i <<
"i";
343 template<
typename Ch,
typename Tr>
344 std::basic_ostream<Ch,Tr>&
operator<<( std::basic_ostream<Ch,Tr>& stream,
345 complex_long_double_ref
const& z ){
346 long double i = z.imag();
347 if( i >= 0 ) stream << z.real() <<
"+" << i <<
"i";
348 else stream << z.real() <<
"-" << -i <<
"i";
362 namespace cpx_long_double {
This class can be used like a pointer for complex_long_double objects so that we can iterate over a v...
complex_long_double_ref const * operator->() const
Dereference the pointer.
complex_long_double_ref operator*()
Dereference the pointer.
complex_long_double_ref const operator*() const
Dereference the pointer.
complex_long_double_ref * operator->()
Dereference the pointer.
complex_long_double_ptr(long double *dat)
Typically we are given a pointer to the data storing the complex_long_double and need to construct a ...
This class can be used like a reference for complex_long_double objects so that we can iterate over a...
complex_long_double_ref & operator=(complex_long_double const &z)
Assignment from complex_long_double.
void set_complex_long_double(long double x, long double y)
C++ version of GSL_SET_COMPLEX().
long double * dat
The data.
complex_long_double_ref()
The default constructor is only really useful for assigning to.
long double imag() const
C++ version of GSL_IMAG().
complex_long_double_ref(complex_long_double &z)
Make sure we can construct from a complex_long_double.
complex_long_double_ref(long double *dat)
We use this in constructing complex_long_double_ptr objects.
void set_real(long double x)
C++ version of GSL_SET_REAL().
void set_imag(long double y)
C++ version of GSL_SET_IMAG().
long double real() const
C++ version of GSL_REAL().
This class handles complex_long_double numbers.
static complex_long_double rect(long double x, long double y)
C++ version of gsl_complex_long_double_rect().
bool operator<=(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
void set_imag(long double y)
C++ version of GSL_SET_IMAG().
long double imag() const
C++ version of GSL_IMAG().
void set_complex_long_double(long double x, long double y)
C++ version of GSL_SET_COMPLEX().
complex_long_double(gsl_complex_long_double const &z)
Constructor from base class.
complex_long_double(long double *dat)
Allow construction from raw data.
bool operator==(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
gsl_complex_long_double & get()
Get the base class object.
bool operator<(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
gsl_complex_long_double const & get() const
Get the base class object.
bool operator>(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
bool operator>=(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
bool operator!=(complex_long_double const &z) const
A complex_long_double object must be less than comparable so that it can be used as a container value...
long double real() const
C++ version of GSL_REAL().
complex_long_double()
The default constructor is only really useful for assigning to.
complex_long_double(std::complex< long double > const &z)
Allow construction from a std::complex<long double>.
void set_real(long double x)
C++ version of GSL_SET_REAL().
static complex_long_double polar(long double r, long double theta)
C++ version of gsl_complex_long_double_rect().
complex_long_double(long double const real, long double const imag)
Allow construction from real and imaginary values.
This class handles matrix_complex_long_double objects as shared handles.
This class handles vector_complex_long_double objects as shared handles.
complex_long_double rect(long double x, long double y)
C++ version of gsl_complex_long_double_rect().
complex_long_double polar(long double r, long double theta)
C++ version of gsl_complex_long_double_rect().
complex cos(complex const &a)
C++ version of gsl_complex_cos().
complex sin(complex const &a)
C++ version of gsl_complex_sin().
The gsl package creates an interface to the GNU Scientific Library for C++.
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.