00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_BALL_COMPLEX_HPP
00014 #define __MMX_BALL_COMPLEX_HPP
00015 #include <numerix/ball_complex_rounded.hpp>
00016 namespace mmx {
00017
00018
00019
00020
00021
00022 template<typename Real, typename Complex, typename R> ball<Complex,R>
00023 complex_gaussian (const ball<Real,R>& re) {
00024 typedef Ball_variant(R) V;
00025 typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00026 ball<Complex,R> z; Impl::gauss (z, re, promote (0, re)); return z;
00027 }
00028
00029 template<typename Real, typename Complex, typename R> ball<Complex,R>
00030 complex_gaussian (const ball<Real,R>& re, const ball<Real,R>& im) {
00031 typedef Ball_variant(R) V;
00032 typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00033 ball<Complex,R> z; Impl::gauss (z, re, im); return z;
00034 }
00035
00036
00037
00038
00039
00040 #define TMPL template<typename C,typename R,typename V>
00041 #define Complex_ball ball<C,R,V>
00042 #define Real Real_type(C)
00043 #define Real_ball ball<Real,R,V>
00044
00045 UNARY_RETURN_TYPE(TMPL,Re_op,Complex_ball,Real_ball );
00046
00047
00048
00049
00050
00051 TMPL inline Real_ball Re (const Complex_ball& z) {
00052 return Real_ball (Re (center (z)), radius (z)); }
00053 TMPL inline Real_ball Im (const Complex_ball& z) {
00054 return Real_ball (Im (center (z)), radius (z)); }
00055 TMPL inline Real_ball arg (const Complex_ball& z) {
00056 return atan2 (Im (z), Re (z)); }
00057 TMPL inline Complex_ball conj (const Complex_ball& z) {
00058 return Complex_ball (conj (center (z)), radius (z)); }
00059 TMPL inline Complex_ball times_i (const Complex_ball& z) {
00060 return Complex_ball (times_i (center (z)), radius (z)); }
00061 TMPL inline Complex_ball over_i (const Complex_ball& z) {
00062 return Complex_ball (over_i (center (z)), radius (z)); }
00063
00064 TMPL inline Complex_ball cmul (const Real_ball& x, const Complex_ball& z) {
00065 return complex_gaussian<Real,C> (x) * z; }
00066 TMPL inline Complex_ball cmul (const Complex_ball& z, const Real_ball& x) {
00067 return z * complex_gaussian<Real,C> (x); }
00068 TMPL inline Complex_ball cdiv (const Real_ball& x, const Complex_ball& z) {
00069 return complex_gaussian<Real,C> (x) / z; }
00070 TMPL inline Complex_ball cdiv (const Complex_ball& z, const Real_ball& x) {
00071 return z / complex_gaussian<Real,C> (x); }
00072
00073 #undef TMPL
00074 #undef Complex_ball
00075 #undef Real
00076 #undef Real_ball
00077
00078
00079
00080
00081
00082 #define TMPL template<typename C,typename R,typename V>
00083 #define Ball ball<C,R,V>
00084 #define Complex_ball ball<complex<C>,R,V>
00085
00086 BINARY_RETURN_TYPE(TMPL,gaussian_op,Ball,Ball,Complex_ball);
00087
00088
00089
00090
00091
00092 TMPL Complex_ball
00093 gaussian (const Ball& re, const Ball& im= 0) {
00094 typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00095 Complex_ball z; Impl::gauss (z, re, im); return z;
00096 }
00097
00098 TMPL Complex_ball
00099 polar (const Ball& r, const Ball& t) {
00100 typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00101 Complex_ball z; Impl::polar (z, r, t); return z;
00102 }
00103
00104
00105
00106
00107
00108 TMPL syntactic
00109 flatten (const Complex_ball& z) {
00110 if (is_nan (z)) return Nan (syntactic);
00111 if (is_fuzz (z)) return Fuzz (syntactic);
00112 if (is_infinite (z)) return Infinity (syntactic);
00113 if (is_exact_zero (z)) return 0;
00114 if (Re (z) != 0 && Im (z) == 0)
00115 return flatten (Re (z));
00116 if (Re (z) == 0 && Im (z) != 0)
00117 return flatten (Im (z)) * Imaginary (syntactic);
00118 return flatten (Re (z)) + flatten (Im (z)) * Imaginary (syntactic);
00119 }
00120
00121 TMPL syntactic
00122 flatten (const Complex_ball& z, nat dd) {
00123 if (is_nan (z)) return Nan (syntactic);
00124 if (is_fuzz (z)) return Fuzz (syntactic);
00125 if (is_infinite (z)) return Infinity (syntactic);
00126 if (is_exact_zero (z)) return 0;
00127 if (Re (z) != 0 && Im (z) == 0)
00128 return flatten (Re (z), dd);
00129 if (Re (z) == 0 && Im (z) != 0)
00130 return flatten (Im (z), dd) * Imaginary (syntactic);
00131 return flatten (Re (z), dd) + flatten (Im (z), dd) * Imaginary (syntactic);
00132 }
00133
00134
00135
00136
00137
00138 TMPL inline Complex_ball operator + (const Complex_ball& z1, const Ball& z2) {
00139 return z1 + Complex_ball (z2); }
00140 TMPL inline Complex_ball operator + (const Ball& z1, const Complex_ball& z2) {
00141 return Complex_ball (z1) + z2; }
00142 TMPL inline Complex_ball operator - (const Complex_ball& z1, const Ball& z2) {
00143 return z1 - Complex_ball (z2); }
00144 TMPL inline Complex_ball operator - (const Ball& z1, const Complex_ball& z2) {
00145 return Complex_ball (z1) - z2; }
00146 TMPL inline Complex_ball operator * (const Complex_ball& z1, const Ball& z2) {
00147 return z1 * Complex_ball (z2); }
00148 TMPL inline Complex_ball operator * (const Ball& z1, const Complex_ball& z2) {
00149 return Complex_ball (z1) * z2; }
00150 TMPL inline Complex_ball operator / (const Complex_ball& z1, const Ball& z2) {
00151 return z1 / Complex_ball (z2); }
00152 TMPL inline Complex_ball operator / (const Ball& z1, const Complex_ball& z2) {
00153 return Complex_ball (z1) / z2; }
00154
00155 #undef TMPL
00156 #undef Ball
00157 #undef Complex_ball
00158 }
00159 #endif // __MMX_BALL_COMPLEX_HPP