library of assembled shared sources

http://lass.cocamware.com

basic_ops.inl

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 // --- implementation details ----------------------------------------------------------------------
00044 
00045 // http://pi.lacim.uqam.ca/eng/table_en.html
00046 #define LASS_NUM_INVLOG2  1.442695040888963407359924681001892137426645954152985934135449406931109219181185079885526622893506344
00047 #define LASS_NUM_INVLOG10 0.434294481903251827651128918916605082294397005803666566114453783165864649208870774729224949338431748
00048     
00049 namespace impl
00050 {
00051 
00052 template <typename T> 
00053 struct IntPow
00054 {
00055     typedef typename NumTraits<T>::signedType TSigned;
00056     typedef typename NumTraits<T>::unsignedType TUnsigned;
00057 
00058     static T eval(TSigned x, TSigned p)
00059     {       
00060         LASS_ASSERT(p >= 0);
00061         return eval(x, static_cast<TUnsigned>(p));
00062     }
00063 
00064     static T eval(TSigned x, TUnsigned p)
00065     {
00066         if (p == 0)
00067         {
00068             return 1;
00069         }
00070 
00071         TSigned result = 0;
00072         TSigned partialPower = 1;
00073         do
00074         {
00075             partialPower *= x;
00076             if (p & 0x1)
00077             {
00078                 result += partialPower;
00079             }
00080             p >>= 1;
00081         }
00082         while (p);
00083         return result;
00084     }
00085 };
00086 
00087 template <typename T> 
00088 struct IntDiv
00089 {
00090     typedef typename NumTraits<T>::signedType TSigned;
00091     typedef typename NumTraits<T>::unsignedType TUnsigned;
00092 
00093     static T eval(TSigned x, TSigned m)
00094     {
00095         LASS_ASSERT(m > 0);
00096         const TSigned tempDiv = x / m;
00097         return x % m >= 0 ? tempDiv : (tempDiv - 1);
00098     }
00099 
00100     static T eval(TSigned x, TUnsigned m)
00101     {
00102         LASS_ASSERT(m > 0);
00103         const TSigned signedMod = static_cast<TSigned>(m);
00104         LASS_ASSERT(signedMod >= 0);
00105         const TSigned tempDiv = x / signedMod;
00106         return x % signedMod >= 0 ? tempDiv : (tempDiv - 1);
00107     }
00108 };
00109 
00110 template <typename T> 
00111 struct IntMod
00112 {
00113     typedef typename NumTraits<T>::signedType TSigned;
00114     typedef typename NumTraits<T>::unsignedType TUnsigned;
00115 
00116     static T eval(TSigned x, TSigned m)
00117     {
00118         LASS_ASSERT(m > 0);
00119         const TSigned tempMod = x % m;
00120         return tempMod >= 0 ? tempMod : (tempMod + m);
00121     }
00122 
00123     static T eval(TSigned x, TUnsigned m)
00124     {
00125         LASS_ASSERT(m > 0);
00126         const TSigned signedMod = static_cast<TSigned>(m);
00127         LASS_ASSERT(signedMod >= 0);
00128         const TSigned tempMod = x % signedMod;
00129         return tempMod >= 0 ? tempMod : (tempMod + signedMod);
00130     }
00131 };
00132 
00133 }
00134 
00135 // --- generic functions ---------------------------------------------------------------------------
00136 
00137 /** if x < 0 return -x, else return x.
00138  *  @ingroup BasicOps
00139  */
00140 template <typename T> inline T abs(const T& x)
00141 {
00142     return x < T() ? -x : x;
00143 }
00144 
00145 /** if x < 0 return -1, else if x > 0 return 1, else return 0.
00146  *  @ingroup BasicOps
00147  */
00148 template <typename T> inline T sign(const T& x)
00149 {
00150     const T zero = T();
00151     return x > zero ? T(1) : (x < zero ? T(-1) : zero);
00152 }
00153 
00154 /** return x * x
00155  *  @ingroup BasicOps
00156  */
00157 template <typename T> inline T sqr(const T& x) 
00158 { 
00159     return x * x; 
00160 }
00161 
00162 /** return x * x * x
00163  *  @ingroup BasicOps
00164  */
00165 template <typename T> inline T cubic(const T& x) 
00166 { 
00167     return x * x * x; 
00168 }
00169 
00170 /** return x ^ -1
00171  *  @ingroup BasicOps
00172  */
00173 template <typename T> inline T inv(const T& x) 
00174 { 
00175     return T(1) / x;
00176 }
00177 
00178 /** return exp(p * log(x));
00179  *  @ingroup BasicOps
00180  *  @warning GENERIC FUNCTION USES EXP AND LOG!
00181  */
00182 template <typename T> inline T pow(const T& x, const T& p) 
00183 { 
00184     return exp(p * log(x));
00185 }
00186 
00187 /** return log(x) / log(2)
00188  *  @ingroup BasicOps
00189  */
00190 template <typename T> inline T log2(const T& x, const T& p) 
00191 { 
00192     return T(LASS_NUM_INVLOG2) * log(x);
00193 }
00194 
00195 /** return log(x) / log(10)
00196  *  @ingroup BasicOps
00197  */
00198 template <typename T> inline T log10(const T& x, const T& p) 
00199 { 
00200     return T(LASS_NUM_INVLOG10) * log(x);
00201 }
00202 
00203 /** return norm of x as if x is real part of complex number: sqr(x)
00204  *  @ingroup BasicOps
00205  */
00206 template <typename T> inline T norm(const T& x)
00207 {
00208     return sqr(x);
00209 }
00210 
00211 /** return conjugate as if x is a complex number: x
00212  */
00213 template <typename T> inline T conj(const T& x)
00214 {
00215     return x;
00216 }
00217 
00218 /** if x < min return min, else if x > max return max, else return x.
00219  *  @ingroup BasicOps
00220  */
00221 template <typename T> inline const T& clamp(const T& x, const T& min, const T& max)
00222 {
00223     return x < min ? min : (x > max ? max : x);
00224 }
00225 
00226 /** linear interpolation between @a a and @a b
00227  *  @ingroup BasicOps
00228  */
00229 template <typename T> inline T lerp(const T& a, const T& b, const T& f)
00230 {
00231     return a + f * (b - a);
00232 }
00233 
00234 /** @ingroup BasicOps
00235  */
00236 template<typename T,typename f> T applyFunction(const T& x, f func ) 
00237 { 
00238     return func(x); 
00239 }
00240 
00241 
00242 
00243 // --- generic inplace rerouters -------------------------------------------------------------------
00244 
00245 template <typename T> void inpabs(T& x)                 { x = num::abs(x); }        /**< @ingroup BasicOps */
00246 template <typename T> void inpsign(T& x)                { x = num::sign(x); }       /**< @ingroup BasicOps */
00247 template <typename T> void inpinv(T& x)                 { x = num::inv(x); }        /**< @ingroup BasicOps */
00248 template <typename T> void inpsqrt(T& x)                { x = num::sqrt(x); }       /**< @ingroup BasicOps */
00249 template <typename T> void inpsqr(T& x)                 { x = num::sqr(x); }        /**< @ingroup BasicOps */
00250 template <typename T> void inpcubic(T& x)               { x = num::cubic(x); }      /**< @ingroup BasicOps */
00251 template <typename T> void inppow(T& x, const T& p)     { x = num::pow(x, p); }     /**< @ingroup BasicOps */
00252 template <typename T> void inpexp(T& x)                 { x = num::exp(x); }        /**< @ingroup BasicOps */
00253 template <typename T> void inplog(T& x)                 { x = num::log(x); }        /**< @ingroup BasicOps */
00254 template <typename T> void inpcos(T& x)                 { x = num::cos(x); }        /**< @ingroup BasicOps */
00255 template <typename T> void inpsin(T& x)                 { x = num::sin(x); }        /**< @ingroup BasicOps */
00256 template <typename T> void inptan(T& x)                 { x = num::tan(x); }        /**< @ingroup BasicOps */
00257 template <typename T> void inpacos(T& x)                { x = num::acos(x); }       /**< @ingroup BasicOps */
00258 template <typename T> void inpasin(T& x)                { x = num::asin(x); }       /**< @ingroup BasicOps */
00259 template <typename T> void inpatan(T& x)                { x = num::atan(x); }       /**< @ingroup BasicOps */
00260 template <typename T> void inpatan2(T& y, const T& x)   { y = num::atan2(y, x); }   /**< @ingroup BasicOps */
00261 template <typename T> void inpfloor(T& x)               { x = num::floor(x); }      /**< @ingroup BasicOps */
00262 template <typename T> void inpceil(T& x)                { x = num::ceil(x); }       /**< @ingroup BasicOps */
00263 template <typename T> void inpround(T& x)               { x = num::round(x); }      /**< @ingroup BasicOps */
00264 template <typename T> void inpfractional(T& x)          { x -= num::floor(x); }     /**< @ingroup BasicOps */
00265 template <typename T> void inpdiv(T& x, const T& m)     { x = num::div(x, m); }     /**< @ingroup BasicOps */
00266 template <typename T> void inpmod(T& x, const T& m)     { x = num::mod(x, m); }     /**< @ingroup BasicOps */
00267 template <typename T> void inpclamp(T& x, const T& min, const T& max)   { x = num::clamp(x, min, max); }    /** @ingroup BasicOps */
00268 
00269 template <typename T> void compnorm(const T& x, T& y)   { y = num::norm(x); }       /**< @ingroup BasicOps */
00270 template <typename T> void compinv(const T& x, T& y)    { y = num::inv(x); }        /**< @ingroup BasicOps */
00271 
00272 
00273 
00274 // --- float ---------------------------------------------------------------------------------------
00275 
00276 float abs(float x)          { return ::fabsf(x); }          /**< @ingroup BasicOps */
00277 float inv(float x)          { return 1.f / x; }             /**< @ingroup BasicOps */
00278 float sqrt(float x)         { LASS_ASSERT(!(x < 0.f)); return ::sqrtf(x); } /**< @ingroup BasicOps */
00279 float pow(float x, float p) { return ::powf(x, p); }        /**< @ingroup BasicOps */
00280 float exp(float x)          { return ::expf(x); }           /**< @ingroup BasicOps */
00281 float log(float x)          { return ::logf(x); }           /**< @ingroup BasicOps */
00282 float log2(float x)         { return float(LASS_NUM_INVLOG2) * ::logf(x); } /**< @ingroup BasicOps */
00283 float log10(float x)        { return ::log10f(x); }         /**< @ingroup BasicOps */
00284 float cos(float x)          { return ::cosf(x); }           /**< @ingroup BasicOps */
00285 float sin(float x)          { return ::sinf(x); }           /**< @ingroup BasicOps */
00286 float tan(float x)          { return ::tanf(x); }           /**< @ingroup BasicOps */
00287 float acos(float x)         { return ::acosf(x); }          /**< @ingroup BasicOps */
00288 float asin(float x)         { return ::asinf(x); }          /**< @ingroup BasicOps */
00289 float atan(float x)         { return ::atanf(x); }          /**< @ingroup BasicOps */
00290 float atan2(float y, float x)   { return ::atan2f(y, x); }  /**< @ingroup BasicOps */
00291 float sinc(float x)         { return ::fabsf(x) < 1e-4f ? 1.f : (::sinf(x) / x); }  /**< @ingroup BasicOps */
00292 float floor(float x)        { return ::floorf(x); }         /**< @ingroup BasicOps */
00293 float ceil(float x)         { return ::ceilf(x); }          /**< @ingroup BasicOps */
00294 float round(float x)        { return ::floorf(x + .5f); }   /**< @ingroup BasicOps */
00295 float fractional(float x)   { return x - ::floorf(x); }     /**< @ingroup BasicOps */
00296 
00297 /** @ingroup BasicOps */
00298 float mod(float x, float m) 
00299 { 
00300     const float result = ::fmodf(x, m);
00301     return result < 0.f ? result + m : result;
00302 }   
00303 
00304 /** @ingroup BasicOps */
00305 float fastSin(float x)
00306 {
00307     const float a = 1.2732395447351628f;
00308     const float b = -0.4052847345693511f;
00309     const float c = 0.2248391028f;
00310     const float y = a * x + b * x * fabsf(x);
00311     return c * (y * fabsf(y) - y) + y;
00312 }
00313 
00314 
00315 // --- double --------------------------------------------------------------------------------------
00316 
00317 double abs(double x)            { return ::fabs(x); }           /**< @ingroup BasicOps */
00318 double inv(double x)            { return 1. / x; }              /**< @ingroup BasicOps */
00319 double sqrt(double x)           { LASS_ASSERT(!(x < 0.)); return ::sqrt(x); }   /**< @ingroup BasicOps */
00320 double pow(double x, double p)  { return ::pow(x, p); }         /**< @ingroup BasicOps */
00321 double exp(double x)            { return ::exp(x); }            /**< @ingroup BasicOps */
00322 double log(double x)            { return ::log(x); }            /**< @ingroup BasicOps */
00323 double log2(double x)           { return double(LASS_NUM_INVLOG2) * ::log(x); } /**< @ingroup BasicOps */
00324 double log10(double x)          { return ::log10(x); }          /**< @ingroup BasicOps */
00325 double cos(double x)            { return ::cos(x); }            /**< @ingroup BasicOps */
00326 double sin(double x)            { return ::sin(x); }            /**< @ingroup BasicOps */
00327 double tan(double x)            { return ::tan(x); }            /**< @ingroup BasicOps */
00328 double acos(double x)           { return ::acos(x); }           /**< @ingroup BasicOps */
00329 double asin(double x)           { return ::asin(x); }           /**< @ingroup BasicOps */
00330 double atan(double x)           { return ::atan(x); }           /**< @ingroup BasicOps */
00331 double atan2(double y, double x)    { return ::atan2(y, x); }   /**< @ingroup BasicOps */
00332 double sinc(double x)           { return ::fabs(x) < 1e-8 ? 1. : (::sin(x) / x); }  /**< @ingroup BasicOps */
00333 double floor(double x)          { return ::floor(x); }          /**< @ingroup BasicOps */
00334 double ceil(double x)           { return ::ceil(x); }           /**< @ingroup BasicOps */
00335 double round(double x)          { return ::floor(x + .5); }     /**< @ingroup BasicOps */
00336 double fractional(double x)     { return x - ::floor(x); }      /**< @ingroup BasicOps */
00337 
00338 /** @ingroup BasicOps */
00339 double mod(double x, double m) 
00340 { 
00341     const double result = ::fmod(x, m);
00342     return result < 0. ? result + m : result;
00343 }   
00344 
00345 /** @ingroup BasicOps */
00346 double fastSin(double x)
00347 {
00348     const double a = 1.2732395447351628;
00349     const double b = -0.4052847345693511;
00350     const double c = 0.2248391028;
00351     const double y = a * x + b * x * fabs(x);
00352     return c * (y * fabs(y) - y) + y;
00353 }
00354 
00355 
00356 
00357 // --- long double ---------------------------------------------------------------------------------
00358 
00359 #ifdef LASS_NUM_BASIC_OPS_USE_BUILTIN_LONG_DOUBLE
00360 
00361 long double abs(long double x)                  { return __builtin_fabsl(x); }      /**< @ingroup BasicOps */
00362 long double inv(long double x)                  { return 1. / x; }                  /**< @ingroup BasicOps */
00363 long double sqrt(long double x)                 { LASS_ASSERT(!(x < 0.)); return __builtin_sqrtl(x); }  /**< @ingroup BasicOps */
00364 long double pow(long double x, long double p)   { return __builtin_powl(x, p); }    /**< @ingroup BasicOps */
00365 long double exp(long double x)                  { return __builtin_expl(x); }       /**< @ingroup BasicOps */
00366 long double log(long double x)                  { return __builtin_logl(x); }       /**< @ingroup BasicOps */
00367 long double log2(long double x)                 { return (long double)(LASS_NUM_INVLOG2) * __builtin_logl(x); } /**< @ingroup BasicOps */
00368 long double log10(long double x)                { return __builtin_log10l(x); }     /**< @ingroup BasicOps */
00369 long double cos(long double x)                  { return __builtin_cosl(x); }       /**< @ingroup BasicOps */
00370 long double sin(long double x)                  { return __builtin_sinl(x); }       /**< @ingroup BasicOps */
00371 long double tan(long double x)                  { return __builtin_tanl(x); }       /**< @ingroup BasicOps */
00372 long double acos(long double x)                 { return __builtin_acosl(x); }      /**< @ingroup BasicOps */
00373 long double asin(long double x)                 { return __builtin_asinl(x); }      /**< @ingroup BasicOps */
00374 long double atan(long double x)                 { return __builtin_atanl(x); }      /**< @ingroup BasicOps */
00375 long double atan2(long double y, long double x) { return __builtin_atan2l(y, x); }  /**< @ingroup BasicOps */
00376 long double sinc(long double x)                 { return __builtin_fabsl(x) < 1e-10 ? 1. : (__builtin_sinl(x) / x); }   /**< @ingroup BasicOps */
00377 long double floor(long double x)                { return __builtin_floorl(x); }     /**< @ingroup BasicOps */
00378 long double ceil(long double x)                 { return __builtin_ceill(x); }      /**< @ingroup BasicOps */
00379 long double round(long double x)                { return __builtin_floorl(x + .5); }    /**< @ingroup BasicOps */
00380 long double fractional(long double x)           { return x - __builtin_floorl(x); } /**< @ingroup BasicOps */
00381 
00382 /** @ingroup BasicOps */
00383 long double mod(long double x, long double m) 
00384 { 
00385     const long double result = __builtin_fmodl(x, m);
00386     return result < 0. ? result + m : result;
00387 }   
00388 
00389 #else
00390 
00391 long double abs(long double x)                  { return ::fabsl(x); }          /**< @ingroup BasicOps */
00392 long double inv(long double x)                  { return 1. / x; }              /**< @ingroup BasicOps */
00393 long double sqrt(long double x)                 { LASS_ASSERT(!(x < 0.)); return ::sqrtl(x); }  /**< @ingroup BasicOps */
00394 long double pow(long double x, long double p)   { return ::powl(x, p); }        /**< @ingroup BasicOps */
00395 long double exp(long double x)                  { return ::expl(x); }           /**< @ingroup BasicOps */
00396 long double log(long double x)                  { return ::logl(x); }           /**< @ingroup BasicOps */
00397 long double log2(long double x)                 { return (long double)(LASS_NUM_INVLOG2) * ::logl(x); } /**< @ingroup BasicOps */
00398 long double log10(long double x)                { return ::log10l(x); }         /**< @ingroup BasicOps */
00399 long double cos(long double x)                  { return ::cosl(x); }           /**< @ingroup BasicOps */
00400 long double sin(long double x)                  { return ::sinl(x); }           /**< @ingroup BasicOps */
00401 long double tan(long double x)                  { return ::tanl(x); }           /**< @ingroup BasicOps */
00402 long double acos(long double x)                 { return ::acosl(x); }          /**< @ingroup BasicOps */
00403 long double asin(long double x)                 { return ::asinl(x); }          /**< @ingroup BasicOps */
00404 long double atan(long double x)                 { return ::atanl(x); }          /**< @ingroup BasicOps */
00405 long double atan2(long double y, long double x) { return ::atan2l(y, x); }      /**< @ingroup BasicOps */
00406 long double sinc(long double x)                 { return ::fabsl(x) < 1e-10 ? 1. : (::sinl(x) / x); }   /**< @ingroup BasicOps */
00407 long double floor(long double x)                { return ::floorl(x); }         /**< @ingroup BasicOps */
00408 long double ceil(long double x)                 { return ::ceill(x); }          /**< @ingroup BasicOps */
00409 long double round(long double x)                { return ::floorl(x + .5); }    /**< @ingroup BasicOps */
00410 long double fractional(long double x)           { return x - ::floorl(x); }     /**< @ingroup BasicOps */
00411 
00412 /** @ingroup BasicOps */
00413 long double mod(long double x, long double m) 
00414 { 
00415     const long double result = ::fmodl(x, m);
00416     return result < 0. ? result + m : result;
00417 }   
00418 
00419 /** @ingroup BasicOps */
00420 long double fastSin(long double x)
00421 {
00422     const long double a = 1.2732395447351628;
00423     const long double b = -0.4052847345693511;
00424     const long double c = 0.2248391028;
00425     const long double y = a * x + b * x * fabs(x);
00426     return c * (y * fabs(y) - y) + y;
00427 }
00428 
00429 #endif
00430 
00431 
00432 // --- char ----------------------------------------------------------------------------------------
00433 
00434 #ifdef LASS_CHAR_IS_SIGNED
00435 
00436 char pow(char x, char p)            { return impl::IntPow<char>::eval(x, static_cast<signed char>(p)); }    /**< @ingroup BasicOps */
00437 char pow(char x, unsigned char p)   { return impl::IntPow<char>::eval(x, p); }  /**< @ingroup BasicOps */
00438 char div(char x, char m)            { return impl::IntDiv<char>::eval(x, static_cast<signed char>(m)); }    /**< @ingroup BasicOps */
00439 char div(char x, unsigned char m)   { return impl::IntDiv<char>::eval(x, m); }  /**< @ingroup BasicOps */
00440 char mod(char x, char m)            { return impl::IntMod<char>::eval(x, static_cast<signed char>(m)); }    /**< @ingroup BasicOps */
00441 char mod(char x, unsigned char m)   { return impl::IntMod<char>::eval(x, m); }  /**< @ingroup BasicOps */
00442 
00443 #else
00444 
00445 char abs(char x)            { return x; }               /**< @ingroup BasicOps */
00446 char sign(char x)           { return x > 0 ? 1 : 0; }   /**< @ingroup BasicOps */
00447 char pow(char x, char p)    { return impl::IntPow<char>::eval(x, static_cast<unsigned char>(p)); }  /**< @ingroup BasicOps */
00448 char div(char x, char p)    { return x / p; }           /**< @ingroup BasicOps */
00449 char mod(char x, char p)    { return x % p; }           /**< @ingroup BasicOps */
00450 
00451 #endif
00452 
00453 char floor(char x)          { return x; }               /**< @ingroup BasicOps */
00454 char ceil(char x)           { return x; }               /**< @ingroup BasicOps */
00455 char round(char x)          { return x; }               /**< @ingroup BasicOps */
00456 char fractional(char /*x*/) { return 0; }               /**< @ingroup BasicOps */
00457 
00458 void inpfloor(char& /*x*/)  {}                          /**< @ingroup BasicOps */
00459 void inpceil(char& /*x*/)   {}                          /**< @ingroup BasicOps */
00460 void inpround(char& /*x*/)  {}                          /**< @ingroup BasicOps */
00461 void inpfractional(char& x) { x = 0; }                  /**< @ingroup BasicOps */
00462 
00463 // --- signed char ----------------------------------------------------------------------------------
00464 
00465 signed char abs(signed char x)                      { return static_cast<signed char>(::abs(x)); }  /**< @ingroup BasicOps */
00466 signed char pow(signed char x, signed char p)       { return impl::IntPow<char>::eval(x, p); }      /**< @ingroup BasicOps */
00467 signed char pow(signed char x, unsigned char p)     { return impl::IntPow<char>::eval(x, p); }      /**< @ingroup BasicOps */
00468 signed char floor(signed char x)                    { return x; }                                   /**< @ingroup BasicOps */
00469 signed char ceil(signed char x)                     { return x; }                                   /**< @ingroup BasicOps */
00470 signed char round(signed char x)                    { return x; }                                   /**< @ingroup BasicOps */
00471 signed char fractional(signed char /*x*/)           { return 0; }                                   /**< @ingroup BasicOps */
00472 signed char div(signed char x, signed char p)       { return impl::IntDiv<char>::eval(x, p); }      /**< @ingroup BasicOps */
00473 signed char div(signed char x, unsigned char p)     { return impl::IntDiv<char>::eval(x, p); }      /**< @ingroup BasicOps */
00474 signed char mod(signed char x, signed char p)       { return impl::IntMod<char>::eval(x, p); }      /**< @ingroup BasicOps */
00475 signed char mod(signed char x, unsigned char p)     { return impl::IntMod<char>::eval(x, p); }      /**< @ingroup BasicOps */
00476 
00477 void inpfloor(signed char& /*x*/)   {}              /**< @ingroup BasicOps */
00478 void inpceil(signed char& /*x*/)    {}              /**< @ingroup BasicOps */
00479 void inpround(signed char& /*x*/)   {}              /**< @ingroup BasicOps */
00480 void inpfractional(signed char& x)  { x = 0; }      /**< @ingroup BasicOps */
00481 
00482 
00483 
00484 // --- unsigned char ----------------------------------------------------------------------------------
00485 
00486 unsigned char abs(unsigned char x)                  { return x; }               /**< @ingroup BasicOps */
00487 unsigned char sign(unsigned char x)                 { return x > 0 ? 1 : 0; }   /**< @ingroup BasicOps */
00488 unsigned char pow(unsigned char x, unsigned char p) { return impl::IntPow<unsigned char>::eval(x, p); } /**< @ingroup BasicOps */
00489 unsigned char floor(unsigned char x)                { return x; }               /**< @ingroup BasicOps */
00490 unsigned char ceil(unsigned char x)                 { return x; }               /**< @ingroup BasicOps */
00491 unsigned char round(unsigned char x)                { return x; }               /**< @ingroup BasicOps */
00492 unsigned char fractional(unsigned char /*x*/)       { return 0; }               /**< @ingroup BasicOps */
00493 unsigned char div(unsigned char x, unsigned char p) { return x / p; }           /**< @ingroup BasicOps */
00494 unsigned char mod(unsigned char x, unsigned char p) { return x % p; }           /**< @ingroup BasicOps */
00495 
00496 void inpabs(unsigned char& /*x*/)       {}          /**< @ingroup BasicOps */
00497 void inpfloor(unsigned char& /*x*/)     {}          /**< @ingroup BasicOps */
00498 void inpceil(unsigned char& /*x*/)      {}          /**< @ingroup BasicOps */
00499 void inpround(unsigned char& /*x*/)     {}          /**< @ingroup BasicOps */
00500 void inpfractional(unsigned char& x)    { x = 0; }  /**< @ingroup BasicOps */
00501 
00502 
00503 
00504 // --- signed short ----------------------------------------------------------------------------------
00505 
00506 signed short abs(signed short x)                    { return static_cast<signed short>(::abs(x)); } /**< @ingroup BasicOps */
00507 signed short pow(signed short x, signed short p)    { return impl::IntPow<short>::eval(x, p); }     /**< @ingroup BasicOps */
00508 signed short pow(signed short x, unsigned short p)  { return impl::IntPow<short>::eval(x, p); }     /**< @ingroup BasicOps */
00509 signed short floor(signed short x)                  { return x; }                                   /**< @ingroup BasicOps */
00510 signed short ceil(signed short x)                   { return x; }                                   /**< @ingroup BasicOps */
00511 signed short round(signed short x)                  { return x; }                                   /**< @ingroup BasicOps */
00512 signed short fractional(signed short /*x*/)         { return 0; }                                   /**< @ingroup BasicOps */
00513 signed short div(signed short x, signed short p)    { return impl::IntDiv<short>::eval(x, p); }     /**< @ingroup BasicOps */
00514 signed short div(signed short x, unsigned short p)  { return impl::IntDiv<short>::eval(x, p); }     /**< @ingroup BasicOps */
00515 signed short mod(signed short x, signed short p)    { return impl::IntMod<short>::eval(x, p); }     /**< @ingroup BasicOps */
00516 signed short mod(signed short x, unsigned short p)  { return impl::IntMod<short>::eval(x, p); }     /**< @ingroup BasicOps */
00517 
00518 void inpfloor(signed short& /*x*/)  {}          /**< @ingroup BasicOps */
00519 void inpceil(signed short& /*x*/)   {}          /**< @ingroup BasicOps */
00520 void inpround(signed short& /*x*/)  {}          /**< @ingroup BasicOps */
00521 void inpfractional(signed short& x) { x = 0; }  /**< @ingroup BasicOps */
00522 
00523 
00524 
00525 // --- unsigned short ----------------------------------------------------------------------------------
00526 
00527 unsigned short abs(unsigned short x)                    { return x; }                                           /**< @ingroup BasicOps */
00528 unsigned short sign(unsigned short x)                   { return x > 0 ? 1 : 0; }                               /**< @ingroup BasicOps */
00529 unsigned short pow(unsigned short x, unsigned short p)  { return impl::IntPow<unsigned short>::eval(x, p); }    /**< @ingroup BasicOps */
00530 unsigned short floor(unsigned short x)                  { return x; }                                           /**< @ingroup BasicOps */
00531 unsigned short ceil(unsigned short x)                   { return x; }                                           /**< @ingroup BasicOps */
00532 unsigned short round(unsigned short x)                  { return x; }                                           /**< @ingroup BasicOps */
00533 unsigned short fractional(unsigned short /*x*/)         { return 0; }                                           /**< @ingroup BasicOps */
00534 unsigned short div(unsigned short x, unsigned short p)  { return x / p; }                                       /**< @ingroup BasicOps */
00535 unsigned short mod(unsigned short x, unsigned short p)  { return x % p; }                                       /**< @ingroup BasicOps */
00536 
00537 void inpabs(unsigned short& /*x*/)      {}          /**< @ingroup BasicOps */
00538 void inpfloor(unsigned short& /*x*/)    {}          /**< @ingroup BasicOps */
00539 void inpceil(unsigned short& /*x*/)     {}          /**< @ingroup BasicOps */
00540 void inpround(unsigned short& /*x*/)    {}          /**< @ingroup BasicOps */
00541 void inpfractional(unsigned short& x)   { x = 0; }  /**< @ingroup BasicOps */
00542 
00543 
00544 
00545 // --- signed int ----------------------------------------------------------------------------------
00546 
00547 signed int abs(signed int x)                    { return ::abs(x); }                        /**< @ingroup BasicOps */
00548 signed int pow(signed int x, signed int p)      { return impl::IntPow<int>::eval(x, p); }   /**< @ingroup BasicOps */
00549 signed int pow(signed int x, unsigned int p)    { return impl::IntPow<int>::eval(x, p); }   /**< @ingroup BasicOps */
00550 signed int floor(signed int x)                  { return x; }                               /**< @ingroup BasicOps */
00551 signed int ceil(signed int x)                   { return x; }                               /**< @ingroup BasicOps */
00552 signed int round(signed int x)                  { return x; }                               /**< @ingroup BasicOps */
00553 signed int fractional(signed int /*x*/)         { return 0; }                               /**< @ingroup BasicOps */
00554 signed int div(signed int x, signed int p)      { return impl::IntDiv<int>::eval(x, p); }   /**< @ingroup BasicOps */
00555 signed int div(signed int x, unsigned int p)    { return impl::IntDiv<int>::eval(x, p); }   /**< @ingroup BasicOps */
00556 signed int mod(signed int x, signed int p)      { return impl::IntMod<int>::eval(x, p); }   /**< @ingroup BasicOps */
00557 signed int mod(signed int x, unsigned int p)    { return impl::IntMod<int>::eval(x, p); }   /**< @ingroup BasicOps */
00558 
00559 void inpfloor(signed int& /*x*/)    {}          /**< @ingroup BasicOps */
00560 void inpceil(signed int& /*x*/)     {}          /**< @ingroup BasicOps */
00561 void inpround(signed int& /*x*/)    {}          /**< @ingroup BasicOps */
00562 void inpfractional(signed int& x)   { x = 0; }  /**< @ingroup BasicOps */
00563 
00564 
00565 
00566 // --- unsigned int ----------------------------------------------------------------------------------
00567 
00568 unsigned int abs(unsigned int x)                    { return x; }                                       /**< @ingroup BasicOps */
00569 unsigned int sign(unsigned int x)                   { return x > 0 ? 1 : 0; }                           /**< @ingroup BasicOps */
00570 unsigned int pow(unsigned int x, unsigned int p)    { return impl::IntPow<unsigned int>::eval(x, p); }  /**< @ingroup BasicOps */
00571 unsigned int floor(unsigned int x)                  { return x; }                                       /**< @ingroup BasicOps */
00572 unsigned int ceil(unsigned int x)                   { return x; }                                       /**< @ingroup BasicOps */
00573 unsigned int round(unsigned int x)                  { return x; }                                       /**< @ingroup BasicOps */
00574 unsigned int fractional(unsigned int /*x*/)         { return 0; }                                       /**< @ingroup BasicOps */
00575 unsigned int div(unsigned int x, unsigned int p)    { return x / p; }                                   /**< @ingroup BasicOps */
00576 unsigned int mod(unsigned int x, unsigned int p)    { return x % p; }                                   /**< @ingroup BasicOps */
00577 
00578 void inpabs(unsigned int& /*x*/)    {}          /**< @ingroup BasicOps */
00579 void inpfloor(unsigned int& /*x*/)  {}          /**< @ingroup BasicOps */
00580 void inpceil(unsigned int& /*x*/)   {}          /**< @ingroup BasicOps */
00581 void inpround(unsigned int& /*x*/)  {}          /**< @ingroup BasicOps */
00582 void inpfractional(unsigned int& x) { x = 0; }  /**< @ingroup BasicOps */
00583 
00584 
00585 
00586 // --- signed long ----------------------------------------------------------------------------------
00587 
00588 signed long abs(signed long x)                      { return ::labs(x); }                       /**< @ingroup BasicOps */
00589 signed long pow(signed long x, signed long p)       { return impl::IntPow<long>::eval(x, p); }  /**< @ingroup BasicOps */
00590 signed long pow(signed long x, unsigned long p)     { return impl::IntPow<long>::eval(x, p); }  /**< @ingroup BasicOps */
00591 signed long floor(signed long x)                    { return x; }                               /**< @ingroup BasicOps */
00592 signed long ceil(signed long x)                     { return x; }                               /**< @ingroup BasicOps */
00593 signed long round(signed long x)                    { return x; }                               /**< @ingroup BasicOps */
00594 signed long fractional(signed long /*x*/)           { return 0; }                               /**< @ingroup BasicOps */
00595 signed long div(signed long x, signed long p)       { return impl::IntDiv<long>::eval(x, p); }  /**< @ingroup BasicOps */
00596 signed long div(signed long x, unsigned long p)     { return impl::IntDiv<long>::eval(x, p); }  /**< @ingroup BasicOps */
00597 signed long mod(signed long x, signed long p)       { return impl::IntMod<long>::eval(x, p); }  /**< @ingroup BasicOps */
00598 signed long mod(signed long x, unsigned long p)     { return impl::IntMod<long>::eval(x, p); }  /**< @ingroup BasicOps */
00599 
00600 void inpfloor(signed long& /*x*/)   {}          /**< @ingroup BasicOps */
00601 void inpceil(signed long& /*x*/)    {}          /**< @ingroup BasicOps */
00602 void inpround(signed long& /*x*/)   {}          /**< @ingroup BasicOps */
00603 void inpfractional(signed long& x)  { x = 0; }  /**< @ingroup BasicOps */
00604 
00605 
00606 
00607 // --- unsigned long ----------------------------------------------------------------------------------
00608 
00609 unsigned long abs(unsigned long x)                  { return x; }   /**< @ingroup BasicOps */
00610 unsigned long sign(unsigned long x)                 { return x > 0 ? 1 : 0; }   /**< @ingroup BasicOps */
00611 unsigned long pow(unsigned long x, unsigned long p) { return impl::IntPow<unsigned long>::eval(x, p); } /**< @ingroup BasicOps */
00612 unsigned long floor(unsigned long x)                { return x; }                                       /**< @ingroup BasicOps */
00613 unsigned long ceil(unsigned long x)                 { return x; }                                       /**< @ingroup BasicOps */
00614 unsigned long round(unsigned long x)                { return x; }                                       /**< @ingroup BasicOps */
00615 unsigned long fractional(unsigned long /*x*/)       { return 0; }                                       /**< @ingroup BasicOps */
00616 unsigned long div(unsigned long x, unsigned long p) { return x / p; }                                   /**< @ingroup BasicOps */
00617 unsigned long mod(unsigned long x, unsigned long p) { return x % p; }                                   /**< @ingroup BasicOps */
00618 
00619 void inpabs(unsigned long& /*x*/)       {}          /**< @ingroup BasicOps */
00620 void inpfloor(unsigned long& /*x*/)     {}          /**< @ingroup BasicOps */
00621 void inpceil(unsigned long& /*x*/)      {}          /**< @ingroup BasicOps */
00622 void inpround(unsigned long& /*x*/)     {}          /**< @ingroup BasicOps */
00623 void inpfractional(unsigned long& x)    { x = 0; }  /**< @ingroup BasicOps */
00624 
00625 
00626 
00627 
00628 // --- complex numbers -----------------------------------------------------------------------------
00629 
00630 template <typename T> std::complex<T> abs( const std::complex<T>& x) { return std::abs( x ); }  /**< @ingroup BasicOps */
00631 template <typename T> std::complex<T> inv( const std::complex<T>& x) { return T(1)/x; } /**< @ingroup BasicOps */
00632 template <typename T> std::complex<T> sqrt( const std::complex<T>& x){ return std::sqrt( x ); } /**< @ingroup BasicOps */
00633 template <typename T> std::complex<T> pow(const std::complex<T>& x, double p) { return std::pow(x, p); }    /**< @ingroup BasicOps */
00634 template <typename T> std::complex<T> exp( const std::complex<T>& x) { return std::exp( x ); }  /**< @ingroup BasicOps */
00635 template <typename T> std::complex<T> log( const std::complex<T>& x) { return std::log( x ); }  /**< @ingroup BasicOps */
00636 template <typename T> std::complex<T> log2( const std::complex<T>& x) { return T(LASS_NUM_INVLOG2) * std::log( x ); }   /**< @ingroup BasicOps */
00637 template <typename T> std::complex<T> log10( const std::complex<T>& x) { return T(LASS_NUM_INVLOG10) * std::log( x ); } /**< @ingroup BasicOps */
00638 template <typename T> std::complex<T> cos( const std::complex<T>& x) { return std::cos( x ); }  /**< @ingroup BasicOps */
00639 template <typename T> std::complex<T> sin( const std::complex<T>& x) { return std::sin( x ); }  /**< @ingroup BasicOps */
00640 template <typename T> std::complex<T> tan( const std::complex<T>& x) { return std::tan( x ); }  /**< @ingroup BasicOps */
00641 template <typename T> std::complex<T> acos( const std::complex<T>& x){ return std::acos( x ); } /**< @ingroup BasicOps */
00642 template <typename T> std::complex<T> asin( const std::complex<T>& x){ return std::asin( x ); } /**< @ingroup BasicOps */
00643 template <typename T> std::complex<T> atan( const std::complex<T>& x){ return std::atan( x ); } /**< @ingroup BasicOps */
00644 
00645 template <typename T> T norm(const std::complex<T>& x) { return std::norm( x ); }   /**< @ingroup BasicOps */
00646 template <typename T> std::complex<T> conj(const std::complex<T>& x) { return std::conj(x); }   /**< @ingroup BasicOps */

Generated on Mon Nov 10 14:20:00 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo