20#ifndef CCGSL_COMPLEX_FLOAT_HPP
21#define CCGSL_COMPLEX_FLOAT_HPP
26#include<gsl/gsl_complex.h>
27#include<gsl/gsl_complex_math.h>
58 memcpy( this->dat, dat, 2 *
sizeof(
float ) );
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<float>()
const {
94 return std::complex<float>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
97 operator std::complex<float>()
const {
98 std::complex<float> z = std::complex<float>( GSL_REAL( *
this ), GSL_IMAG( *
this ) );
106 gsl_complex_float&
get(){
return dynamic_cast<gsl_complex_float&
>( *this ); }
111 gsl_complex_float
const&
get()
const {
return dynamic_cast<gsl_complex_float const&
>( *this ); }
126 GSL_SET_COMPLEX( &z, r *
std::cos( theta ), r *
std::sin( theta ) );
return z; }
137 float real()
const {
return GSL_REAL( *
this ); }
142 float imag()
const {
return GSL_IMAG( *
this ); }
147 void set_real(
float x ){ GSL_SET_REAL(
this, x ); }
152 void set_imag(
float 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_float()
const {
221 gsl_complex_float z; memcpy( z.dat,
dat, 2 *
sizeof(
float ) );
return z; }
247 memcpy(
dat, z.dat, 2 *
sizeof(
float ) );
return *
this; }
259 float real()
const {
return GSL_REAL( *
this ); }
264 float imag()
const {
return GSL_IMAG( *
this ); }
269 void set_real(
float x ){ GSL_SET_REAL(
this, x ); }
274 void set_imag(
float 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_float
const& z ){
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_float_ref
const& z ){
347 if( i >= 0 ) stream << z.real() <<
"+" << i <<
"i";
348 else stream << z.real() <<
"-" << -i <<
"i";
362 namespace cpx_float {
This class can be used like a pointer for complex_float objects so that we can iterate over a vector ...
complex_float_ref * operator->()
Dereference the pointer.
complex_float_ptr(float *dat)
Typically we are given a pointer to the data storing the complex_float and need to construct a comple...
complex_float_ref operator*()
Dereference the pointer.
complex_float_ref const * operator->() const
Dereference the pointer.
complex_float_ref const operator*() const
Dereference the pointer.
This class can be used like a reference for complex_float objects so that we can iterate over a vecto...
float real() const
C++ version of GSL_REAL().
complex_float_ref(complex_float &z)
Make sure we can construct from a complex_float.
complex_float_ref(float *dat)
We use this in constructing complex_float_ptr objects.
float imag() const
C++ version of GSL_IMAG().
void set_complex_float(float x, float y)
C++ version of GSL_SET_COMPLEX().
void set_imag(float y)
C++ version of GSL_SET_IMAG().
void set_real(float x)
C++ version of GSL_SET_REAL().
complex_float_ref & operator=(complex_float const &z)
Assignment from complex_float.
complex_float_ref()
The default constructor is only really useful for assigning to.
This class handles complex_float numbers.
bool operator<(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
complex_float(gsl_complex_float const &z)
Constructor from base class.
gsl_complex_float & get()
Get the base class object.
complex_float(float *dat)
Allow construction from raw data.
bool operator!=(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
void set_real(float x)
C++ version of GSL_SET_REAL().
bool operator==(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
complex_float(std::complex< float > const &z)
Allow construction from a std::complex<float>.
gsl_complex_float const & get() const
Get the base class object.
float real() const
C++ version of GSL_REAL().
static complex_float rect(float x, float y)
C++ version of gsl_complex_float_rect().
void set_complex_float(float x, float y)
C++ version of GSL_SET_COMPLEX().
void set_imag(float y)
C++ version of GSL_SET_IMAG().
bool operator>=(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
bool operator<=(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
static complex_float polar(float r, float theta)
C++ version of gsl_complex_float_rect().
complex_float(float const real, float const imag)
Allow construction from real and imaginary values.
float imag() const
C++ version of GSL_IMAG().
complex_float()
The default constructor is only really useful for assigning to.
bool operator>(complex_float const &z) const
A complex_float object must be less than comparable so that it can be used as a container value type.
This class handles matrix_complex_float objects as shared handles.
This class handles vector_complex_float objects as shared handles.
complex_float rect(float x, float y)
C++ version of gsl_complex_float_rect().
complex_float polar(float r, float theta)
C++ version of gsl_complex_float_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++.
gsl_const_complex_packed_float complex_const_packed_float
Typedef.
gsl_const_complex_packed_array_float complex_const_packed_array_float
Typedef.
gsl_complex_packed_float_ptr complex_packed_float_ptr
Typedef.
gsl_const_complex_packed_float_ptr complex_const_packed_float_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.
gsl_complex_packed_float complex_packed_float
Typedef.
gsl_complex_packed_array_float complex_packed_array_float
Typedef.