interval.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_INTERVAL_H
00046 #define LASS_GUARDIAN_OF_INCLUSION_NUM_INTERVAL_H
00047
00048 #include "num_common.h"
00049 #include "num_traits.h"
00050 #include "../util/call_traits.h"
00051 #include "../util/pyobject_plus.h"
00052 #include <iostream>
00053
00054 namespace lass
00055 {
00056 namespace num
00057 {
00058
00059 template<typename C> class interval;
00060
00061 template<typename C> void inpsqr(interval<C>& i);
00062 template<typename C> void inpsqrt(interval<C>& i);
00063 template<typename C> void inpexp(interval<C>& i);
00064 template<typename C> void inplog(interval<C>& i);
00065 template<typename C> void inpnorm(interval<C>& i);
00066 template<typename C> void inpinv(interval<C>& i);
00067 template<typename C, typename F> interval<C> applyFunction(const interval<C>& i, F func);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 template<typename C>
00078 class interval
00079 {
00080 private:
00081 C v[2];
00082 public:
00083 typedef C baseType;
00084
00085 static const interval<C> empty;
00086
00087 inline interval() { v[0]=v[1]=C();};
00088 inline ~interval() {};
00089 inline explicit interval(typename util::CallTraits<baseType>::TParam iValue);
00090 inline explicit interval(typename util::CallTraits<baseType>::TParam iInf,typename util::CallTraits<baseType>::TParam iSup);
00091 inline interval& operator=(const interval<C>& i);
00092
00093 inline const interval& operator+() const;
00094 inline interval operator-() const;
00095
00096
00097 inline void set( typename util::CallTraits<C>::TParam iInf,typename util::CallTraits<C>::TParam iSup);
00098
00099 inline bool isEmpty() const;
00100
00101 inline bool isSingleton() const;
00102
00103 inline bool contains(typename util::CallTraits<baseType>::TParam ix) const;
00104
00105
00106 inline baseType& operator[](int i);
00107
00108 inline baseType operator[](int i) const;
00109
00110 inline baseType inf() const;
00111
00112 inline baseType sup() const;
00113
00114 inline baseType& inf();
00115
00116 inline baseType& sup();
00117
00118 inline baseType mid() const;
00119
00120 inline baseType diam()const;
00121
00122 inline baseType ratio() const;
00123
00124
00125 inline bool operator> (const interval<C>& i) const;
00126
00127 inline bool operator< (const interval<C>& i) const;
00128
00129 inline bool operator==(const interval<C>& i) const;
00130
00131 inline bool operator!=(const interval<C>& i) const;
00132
00133 inline bool operator>=(const interval<C>& i) const;
00134
00135 inline bool operator<=(const interval<C>& i) const;
00136
00137
00138 inline bool pe(const interval<C>& i) const;
00139
00140 inline bool pne(const interval<C>& i) const;
00141
00142 inline bool pg(const interval<C>& i) const;
00143
00144 inline bool pge(const interval<C>& i) const;
00145
00146 inline bool pl(const interval<C>& i) const;
00147
00148 inline bool ple(const interval<C>& i) const;
00149
00150
00151 baseType fe(const interval<C>& i) const;
00152
00153 inline C fne(const interval<C>& i) const;
00154
00155 baseType fg(const interval<C>& i) const;
00156
00157 baseType fge(const interval<C>& i) const;
00158
00159 baseType fl(const interval<C>& i) const;
00160
00161 baseType fle(const interval<C>& i) const;
00162
00163 inline interval& operator+=(const interval<C>& i);
00164 inline interval& operator-=(const interval<C>& i);
00165 inline interval& operator*=(const interval<C>& i);
00166 interval& operator/=(const interval<C>& i);
00167
00168 inline interval& operator+=(typename util::CallTraits<baseType>::TParam s);
00169 inline interval& operator-=(typename util::CallTraits<baseType>::TParam s);
00170 inline interval& operator*=(typename util::CallTraits<baseType>::TParam s);
00171 inline interval& operator/=(typename util::CallTraits<baseType>::TParam s);
00172
00173 friend void inpsqr<C>(interval<C>& i);
00174 friend void inpsqrt<C>(interval<C>& i);
00175 friend void inpexp<C>(interval<C>& i);
00176 friend void inplog<C>(interval<C>& i);
00177 friend void inpnorm<C>(interval<C>& i);
00178 friend void inpinv<C>(interval<C>& i);
00179
00180 template<typename C2, typename F> friend interval<C2> applyFunction(const interval<C2>& iV, F func );
00181
00182 };
00183
00184 template<typename C> interval<C> operator+(const interval<C>& i1,const interval<C>& i2);
00185 template<typename C> interval<C> operator-(const interval<C>& i1,const interval<C>& i2);
00186 template<typename C> interval<C> operator*(const interval<C>& i1,const interval<C>& i2);
00187 template<typename C> interval<C> operator/(const interval<C>& i1,const interval<C>& i2);
00188
00189 template<typename C> std::ostream& operator<<( std::ostream& os, const interval<C>& iV );
00190 template<typename C> std::string str( const interval<C>& iV );
00191
00192 template<typename C> const interval<C> interval<C>::empty = interval<C>(NumTraits<C>::one, NumTraits<C>::zero);
00193
00194
00195
00196 template<typename C> interval<C> sqr(const interval<C>& i);
00197 template<typename C> interval<C> sqrt(const interval<C>& i);
00198 template<typename C> interval<C> exp(const interval<C>& i);
00199 template<typename C> interval<C> log(const interval<C>& i);
00200
00201 template<typename C> interval<C> set_union(const interval<C>& i1, const interval<C>& i2);
00202 template<typename C> interval<C> set_intersect(const interval<C>& i1, const interval<C>& i2);
00203
00204
00205
00206 template< class C >
00207 struct NumTraits< interval<C> >
00208 {
00209 typedef interval<C> selfType;
00210 typedef C baseType;
00211 typedef C intervalType;
00212
00213 enum
00214 {
00215 isDistribution = 1,
00216 isIntegral = 0,
00217 isNative = 0,
00218 isSigned = 1,
00219 hasInfinity = 0,
00220 };
00221
00222 static const size_t memorySize;
00223 static const std::string name();
00224
00225 static const interval<C> one;
00226 static const interval<C> zero;
00227
00228 static const interval<C> epsilon;
00229 static const interval<C> min;
00230 static const interval<C> max;
00231 static const interval<C> minStrictPositive;
00232 static const interval<C> pi;
00233 static const interval<C> e;
00234 static const interval<C> sqrt2;
00235 static const interval<C> sqrtPi;
00236 };
00237
00238
00239 template<class C> const size_t NumTraits<interval<C> >::memorySize = sizeof(interval<C>);
00240 template<class C> const std::string NumTraits<interval<C> >::name() { return std::string("interval<")+NumTraits<baseType>::name()+ std::string(">"); }
00241
00242 template<class C> const interval<C> NumTraits<interval<C> >::one = interval<C>( NumTraits<C>::one );
00243 template<class C> const interval<C> NumTraits<interval<C> >::zero = interval<C>( NumTraits<C>::zero );
00244
00245 template<class C> const interval<C> NumTraits<interval<C> >::epsilon = interval<C>( NumTraits<C>::epsilon );
00246 template<class C> const interval<C> NumTraits<interval<C> >::min = interval<C>( NumTraits<C>::min );
00247 template<class C> const interval<C> NumTraits<interval<C> >::max = interval<C>( NumTraits<C>::max );
00248 template<class C> const interval<C> NumTraits<interval<C> >::minStrictPositive = interval<C>( NumTraits<C>::minStrictPositive );
00249 template<class C> const interval<C> NumTraits<interval<C> >::pi = interval<C>( NumTraits<C>::pi );
00250 template<class C> const interval<C> NumTraits<interval<C> >::e = interval<C>( NumTraits<C>::e );
00251 template<class C> const interval<C> NumTraits<interval<C> >::sqrt2 = interval<C>( NumTraits<C>::sqrt2 );
00252 template<class C> const interval<C> NumTraits<interval<C> >::sqrtPi = interval<C>( NumTraits<C>::sqrtPi );
00253
00254 #include "interval.inl"
00255
00256 }
00257
00258 namespace python
00259 {
00260 template<class C> int pyGetSimpleObject_deprecated( PyObject* iValue, lass::num::interval<C>& oV )
00261 {
00262 std::pair<C,C> temp;
00263 int r=PyExportTraits<std::pair<C,C> >::get(iValue, temp);
00264 if (r==0)
00265 {
00266 oV.set(temp.first , temp.second);
00267 }
00268 return r;
00269 }
00270 template<class C> PyObject* pyBuildSimpleObject_deprecated( const lass::num::interval<C>& iV )
00271 {
00272 return PyExportTraits<std::pair<C,C> >::build( std::pair<C,C>(iV.inf(),iV.sup()) );
00273 }
00274 PYEXPORTTRAITS_USINGDEPRECATED_TEMPL( lass::num::interval )
00275
00276 }
00277
00278 }
00279
00280
00281 #endif