numerix_doc 0.4
/Users/mourrain/Devel/mmx/numerix/include/numerix/ball_complex.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : ball_complex.hpp
00004 * DESCRIPTION: Complex balls
00005 * COPYRIGHT  : (C) 2006  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 * Constructors
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 * General complex balls
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 * Extra arithmetic operations
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 #undef TMPL
00065 #undef Complex_ball
00066 #undef Real
00067 #undef Real_ball
00068 
00069 /******************************************************************************
00070 * Complex balls with center type of the form complex<Real>
00071 ******************************************************************************/
00072 
00073 #define TMPL template<typename C,typename R,typename V>
00074 #define Ball ball<C,R,V>
00075 #define Complex_ball ball<complex<C>,R,V>
00076 
00077 BINARY_RETURN_TYPE(TMPL,gaussian_op,Ball,Ball,Complex_ball);
00078 
00079 /******************************************************************************
00080 * Extra constructors
00081 ******************************************************************************/
00082 
00083 TMPL Complex_ball
00084 gaussian (const Ball& re, const Ball& im= 0) {
00085   typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00086   Complex_ball z; Impl::gauss (z, re, im); return z;
00087 }
00088 
00089 TMPL Complex_ball
00090 polar (const Ball& r, const Ball& t) {
00091   typedef implementation<ball_complex_construct,ball_complex<V> > Impl;
00092   Complex_ball z; Impl::polar (z, r, t); return z;
00093 }
00094 
00095 /******************************************************************************
00096 * Customized output routine
00097 ******************************************************************************/
00098 
00099 TMPL syntactic
00100 flatten (const Complex_ball& z) {
00101   if (is_nan (z)) return Nan (syntactic);
00102   if (is_fuzz (z)) return Fuzz (syntactic);
00103   if (is_infinite (z)) return Infinity (syntactic);
00104   if (is_exact_zero (z)) return 0;
00105   if (Re (z) != 0 && Im (z) == 0)
00106     return flatten (Re (z));
00107   if (Re (z) == 0 && Im (z) != 0)
00108     return flatten (Im (z)) * Imaginary (syntactic);
00109   return flatten (Re (z)) + flatten (Im (z)) * Imaginary (syntactic);
00110 }
00111 
00112 TMPL syntactic
00113 flatten (const Complex_ball& z, nat dd) {
00114   if (is_nan (z)) return Nan (syntactic);
00115   if (is_fuzz (z)) return Fuzz (syntactic);
00116   if (is_infinite (z)) return Infinity (syntactic);
00117   if (is_exact_zero (z)) return 0;
00118   if (Re (z) != 0 && Im (z) == 0)
00119     return flatten (Re (z), dd);
00120   if (Re (z) == 0 && Im (z) != 0)
00121     return flatten (Im (z), dd) * Imaginary (syntactic);
00122   return flatten (Re (z), dd) + flatten (Im (z), dd) * Imaginary (syntactic);
00123 }
00124 
00125 /******************************************************************************
00126 * Extra convenience arithmetic operations
00127 ******************************************************************************/
00128 
00129 TMPL inline Complex_ball operator + (const Complex_ball& z1, const Ball& z2) {
00130   return z1 + Complex_ball (z2); }
00131 TMPL inline Complex_ball operator + (const Ball& z1, const Complex_ball& z2) {
00132   return Complex_ball (z1) + z2; }
00133 TMPL inline Complex_ball operator - (const Complex_ball& z1, const Ball& z2) {
00134   return z1 - Complex_ball (z2); }
00135 TMPL inline Complex_ball operator - (const Ball& z1, const Complex_ball& z2) {
00136   return Complex_ball (z1) - z2; }
00137 TMPL inline Complex_ball operator * (const Complex_ball& z1, const Ball& z2) {
00138   return z1 * Complex_ball (z2); }
00139 TMPL inline Complex_ball operator * (const Ball& z1, const Complex_ball& z2) {
00140   return Complex_ball (z1) * z2; }
00141 TMPL inline Complex_ball operator / (const Complex_ball& z1, const Ball& z2) {
00142   return z1 / Complex_ball (z2); }
00143 TMPL inline Complex_ball operator / (const Ball& z1, const Complex_ball& z2) {
00144   return Complex_ball (z1) / z2; }
00145 
00146 #undef TMPL
00147 #undef Ball
00148 #undef Complex_ball
00149 } // namespace mmx
00150 #endif // __MMX_BALL_COMPLEX_HPP
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines