realroot_doc 0.1.1
/Users/mourrain/Devel/mmx/realroot/include/realroot/Interval_glue.hpp
Go to the documentation of this file.
00001 #ifndef realroot_interval_glue_hpp
00002 #define realroot_interval_glue_hpp
00003 /******************************************************************************/
00004 #include <basix/glue.hpp>
00005 #include <numerix/interval.hpp>
00006 
00007 #define FORALL(X) template<class X> 
00008 #define Interval interval<C>
00009 
00010 namespace mmx
00011 {
00012   FORALL(C) inline mmx::nat hash(const Interval& p){ return 1;}
00013 //   FORALL(C) inline mmx::nat soft_hash(const Interval& p){ return 1;}
00014 //   FORALL(C) inline bool eq(const Interval& p, const Interval& q){ return p==q;}
00015 
00016 
00017   FORALL(C) syntactic flatten(const Interval & x)
00018   {
00019     return flatten(cons(as<generic>(lower(x)), list<generic>(as<generic>(upper(x)))));
00020   }
00021 
00022 
00023   FORALL(C) Interval 
00024   interval_from_pair (const C& a, const C& b) 
00025   {
00026     return Interval(a,b);
00027   }
00028 
00029   FORALL(C) inline C interval_lower (const Interval& I) {return lower(I);}
00030   FORALL(C) inline C interval_upper (const Interval& I) {return upper(I);}
00031 
00032 
00033   template<typename T, typename F>
00034   struct as_helper< interval<T>,interval<F> >
00035   {
00036     static inline 
00037     interval<T> cv (const interval<F>& x) 
00038     {
00039       return interval<T>(as<T>(lower(x)),as<T>(upper(x)));
00040     }
00041   };
00042 
00043   //--------------------------------------------------------------------
00044   FORALL(C) Interval operator+( const Interval& I, const C& c)
00045   {
00046     return I+ Interval(c,c);
00047   }
00048   FORALL(C) Interval operator+(  const C& c, const Interval& I)
00049   {
00050     return Interval(c,c)+I;
00051   }
00052 
00053   FORALL(C) Interval operator-( const Interval& I, const C& c)
00054   {
00055     return I- Interval(c,c);
00056   }
00057   FORALL(C) Interval operator-(  const C& c, const Interval& I)
00058   {
00059     return Interval(c,c)-I;
00060   }
00061 
00062   FORALL(C) Interval operator*( const Interval& I, const C& c)
00063   {
00064     return I* Interval(c,c);
00065   }
00066   FORALL(C) Interval operator*(  const C& c, const Interval& I)
00067   {
00068     return Interval(c,c)*I;
00069   }
00070 
00071   //--------------------------------------------------------------------
00072   FORALL(C) C interval_size (const Interval& p) 
00073   {
00074     return upper(p)-lower(p); 
00075   }
00076 
00077 } // namespace mmx
00078 //--------------------------------------------------------------------
00079 #undef Interval
00080 #undef FORALL
00081 
00082 #endif //realroot_interval_glue_hpp