Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShInterval.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHINTERVAL_HPP
00028 #define SHINTERVAL_HPP
00029 
00030 #include <iostream>
00031 
00032 namespace SH {
00033 
00034 /*** Sh class for standard floating point interval arithmetic, without rounding
00035  *
00036  * Derived from NuS.hh and NuS.cc from the MetaMedia project.
00037  *
00038  * Currently does not handle rounding errors yet 
00039  */
00040 template<typename T>
00041 struct ShInterval {
00042   typedef T DataType;
00043   T m_lo;
00044   T m_hi;
00045 
00047   ShInterval();
00048 
00050   ShInterval(const T& value);
00051 
00053   ShInterval(const T& lo, const T& hi);
00054 
00055   template<typename T2>
00056   ShInterval(const ShInterval<T2> &other);
00057 
00059   // @todo why are these even here if m_lo, m_hi are public?
00060   // @todo why are m_lo and m_hi public?
00061   T& lo();
00062   const T& lo() const;
00063 
00064   T& hi();
00065   const T& hi() const;
00066 
00069   const T& width() const;
00070 
00072   const T& centre() const;
00073 
00075   const T& radius() const;
00076 
00078   ShInterval& operator=(const T &value);
00079   ShInterval& operator=(const ShInterval<T> &other);
00080   ShInterval& operator+=(const T &value);
00081   ShInterval& operator+=(const ShInterval<T> &other);
00082   ShInterval& operator-=(const T &value);
00083   ShInterval& operator-=(const ShInterval<T> &other);
00084   ShInterval& operator*=(const T &value);
00085   ShInterval& operator*=(const ShInterval<T> &other);
00086   ShInterval& operator/=(const T &value);
00087   ShInterval& operator/=(const ShInterval<T> &other);
00088 
00091   ShInterval& operator%=(const T &value);
00092   ShInterval& operator%=(const ShInterval<T> &other);
00093   // @}
00094 
00098   ShInterval operator-() const;
00099 
00101   template<typename TT>
00102   friend std::ostream& operator<<(std::ostream& out, const ShInterval<TT> &value);
00103 
00104 
00106   template<typename TT>
00107   friend std::istream& operator>>(std::istream& out, ShInterval<TT> &value);
00108 
00109 };
00110 
00112 // TODO fill in the remaining interval with scalar ops
00113 template<typename T>
00114 ShInterval<T> operator+(const ShInterval<T> &a, const ShInterval<T> &b);
00115 
00116 template<typename T>
00117 ShInterval<T> operator-(const ShInterval<T> &a, const ShInterval<T> &b);
00118 
00119 template<typename T>
00120 ShInterval<T> operator-(const T &a, const ShInterval<T> &b);
00121 
00122 template<typename T>
00123 ShInterval<T> operator*(const ShInterval<T> &a, const ShInterval<T> &b);
00124 
00125 template<typename T>
00126 ShInterval<T> operator/(const ShInterval<T> &a, const ShInterval<T> &b);
00127 
00128 template<typename T>
00129 ShInterval<T> operator%(const ShInterval<T> &a, const ShInterval<T> &b);
00130 
00131 template<typename T>
00132 ShInterval<T> cbrt(const ShInterval<T> &a);
00133 
00134 template<typename T>
00135 ShInterval<T> exp(const ShInterval<T> &a);
00136 
00137 template<typename T>
00138 ShInterval<T> exp2(const ShInterval<T> &a);
00139 
00140 template<typename T>
00141 ShInterval<T> exp10(const ShInterval<T> &a);
00142 
00143 template<typename T>
00144 ShInterval<T> log(const ShInterval<T> &a);
00145 
00146 template<typename T>
00147 ShInterval<T> log2(const ShInterval<T> &a);
00148 
00149 template<typename T>
00150 ShInterval<T> log10(const ShInterval<T> &a);
00151 
00152 template<typename T>
00153 ShInterval<T> frac(const ShInterval<T> &a);
00154 
00155 template<typename T>
00156 ShInterval<T> fmod(const ShInterval<T> &a, const ShInterval<T> &b);
00157 
00158 template<typename T>
00159 ShInterval<T> pow(const ShInterval<T> &a, const ShInterval<T> &b);
00160 
00161 template<typename T>
00162 ShInterval<T> rcp(const ShInterval<T> &a);
00163 
00164 template<typename T>
00165 ShInterval<T> rsq(const ShInterval<T> &a);
00166 
00167 template<typename T>
00168 ShInterval<T> sgn(const ShInterval<T> &a);
00169 
00170 template<typename T>
00171 ShInterval<T> sqrt(const ShInterval<T> &a);
00172 
00174 template<typename T>
00175 ShInterval<T> acos(const ShInterval<T> &a);
00176 
00177 template<typename T>
00178 ShInterval<T> asin(const ShInterval<T> &a);
00179 
00180 template<typename T>
00181 ShInterval<T> atan(const ShInterval<T> &a);
00182 
00183 template<typename T>
00184 ShInterval<T> atan2(const ShInterval<T> &a, const ShInterval<T> &b);
00185 
00186 template<typename T>
00187 ShInterval<T> cos(const ShInterval<T> &a); 
00188 template<typename T>
00189 ShInterval<T> sin(const ShInterval<T> &a);
00190 
00191 template<typename T>
00192 ShInterval<T> tan(const ShInterval<T> &a);
00193 
00195 // @todo should think about how to represent tri-state logic values.
00196 // For now output is interval (follows the t x t -> t convention of
00197 // types for the standard operators)
00198 template<typename T>
00199 ShInterval<T> operator<(const ShInterval<T> &a, const ShInterval<T> &b);
00200 
00201 template<typename T>
00202 ShInterval<T> operator<=(const ShInterval<T> &a, const ShInterval<T> &b);
00203 
00204 template<typename T>
00205 ShInterval<T> operator>(const ShInterval<T> &a, const ShInterval<T> &b);
00206 
00207 template<typename T>
00208 ShInterval<T> operator>(const ShInterval<T> &a, const T& b); 
00209 
00210 template<typename T>
00211 ShInterval<T> operator>=(const ShInterval<T> &a, const ShInterval<T> &b);
00212 
00213 template<typename T>
00214 ShInterval<T> operator==(const ShInterval<T> &a, const ShInterval<T> &b);
00215 
00216 template<typename T>
00217 ShInterval<T> operator!=(const ShInterval<T> &a, const ShInterval<T> &b);
00218 
00220 template<typename T>
00221 bool boundsEqual(const ShInterval<T> &a);
00222 
00223 
00225 template<typename T>
00226 ShInterval<T> min(const ShInterval<T> &a, const ShInterval<T> &b);
00227 
00228 template<typename T>
00229 ShInterval<T> max(const ShInterval<T> &a, const ShInterval<T> &b);
00230 
00231 template<typename T>
00232 ShInterval<T> floor(const ShInterval<T> &a);
00233 
00234 template<typename T>
00235 ShInterval<T> ceil(const ShInterval<T> &a);
00236 
00237 template<typename T>
00238 ShInterval<T> rnd(const ShInterval<T> &a);
00239 
00240 template<typename T>
00241 ShInterval<T> abs(const ShInterval<T> &a);
00242 
00244 template<typename T>
00245 ShInterval<T> cond(const ShInterval<T> &a, const ShInterval<T> &b, const ShInterval<T> &c);
00246 
00247 template<typename T>
00248 ShInterval<T> lerp(const ShInterval<T> &a, const ShInterval<T> &b, const ShInterval<T> &c);
00249 }
00250 
00251 #include "ShIntervalImpl.hpp"
00252   
00253 #endif

Generated on Mon Jan 24 18:36:32 2005 for Sh by  doxygen 1.4.1