SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

include/tvmet/VectorUnaryFunctions.h

Go to the documentation of this file.
00001 /*
00002  * Tiny Vector Matrix Library
00003  * Dense Vector Matrix Libary of Tiny size using Expression Templates
00004  *
00005  * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: VectorUnaryFunctions.h,v 1.13 2007-06-23 15:58:58 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_VECTOR_UNARY_FUNCTIONS_H
00025 #define TVMET_VECTOR_UNARY_FUNCTIONS_H
00026 
00027 namespace tvmet {
00028 
00029 
00030 /*********************************************************
00031  * PART I: DECLARATION
00032  *********************************************************/
00033 
00034 /*
00035  * unary_function(Vector<T, Sz>)
00036  */
00037 #define TVMET_DECLARE_MACRO(NAME)     \
00038 template<class T, std::size_t Sz>     \
00039 XprVector<            \
00040   XprUnOp<            \
00041     Fcnl_##NAME<T>,         \
00042     VectorConstReference<T, Sz>       \
00043   >,              \
00044   Sz              \
00045 >             \
00046 NAME(const Vector<T, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;
00047 
00048 TVMET_DECLARE_MACRO(abs)
00049 TVMET_DECLARE_MACRO(cbrt)
00050 TVMET_DECLARE_MACRO(ceil)
00051 TVMET_DECLARE_MACRO(floor)
00052 TVMET_DECLARE_MACRO(rint)
00053 TVMET_DECLARE_MACRO(sin)
00054 TVMET_DECLARE_MACRO(cos)
00055 TVMET_DECLARE_MACRO(tan)
00056 TVMET_DECLARE_MACRO(sinh)
00057 TVMET_DECLARE_MACRO(cosh)
00058 TVMET_DECLARE_MACRO(tanh)
00059 TVMET_DECLARE_MACRO(asin)
00060 TVMET_DECLARE_MACRO(acos)
00061 TVMET_DECLARE_MACRO(atan)
00062 TVMET_DECLARE_MACRO(exp)
00063 TVMET_DECLARE_MACRO(log)
00064 TVMET_DECLARE_MACRO(log10)
00065 TVMET_DECLARE_MACRO(sqrt)
00066 
00067 #if defined(TVMET_HAVE_IEEE_MATH)
00068 TVMET_DECLARE_MACRO(asinh)
00069 TVMET_DECLARE_MACRO(acosh)
00070 TVMET_DECLARE_MACRO(atanh)
00071 TVMET_DECLARE_MACRO(expm1)
00072 TVMET_DECLARE_MACRO(log1p)
00073 TVMET_DECLARE_MACRO(erf)
00074 TVMET_DECLARE_MACRO(erfc)
00075 TVMET_DECLARE_MACRO(j0)
00076 TVMET_DECLARE_MACRO(j1)
00077 TVMET_DECLARE_MACRO(y0)
00078 TVMET_DECLARE_MACRO(y1)
00079 TVMET_DECLARE_MACRO(lgamma)
00081 #if !defined(TVMET_NO_IEEE_MATH_ISNAN)
00082 TVMET_DECLARE_MACRO(isnan)
00083 #endif
00084 #if !defined(TVMET_NO_IEEE_MATH_ISINF)
00085 TVMET_DECLARE_MACRO(isinf)
00086 #endif
00087 TVMET_DECLARE_MACRO(finite)
00088 #endif // defined(TVMET_HAVE_IEEE_MATH)
00089 
00090 #undef TVMET_DECLARE_MACRO
00091 
00092 
00093 /*
00094  * unary_function(Vector<std::complex<T>, Sz>)
00095  */
00096 #if defined(TVMET_HAVE_COMPLEX)
00097 #define TVMET_DECLARE_MACRO(NAME)         \
00098 template<class T, std::size_t Sz>         \
00099 XprVector<                \
00100   XprUnOp<                \
00101     Fcnl_##NAME< std::complex<T> >,         \
00102     VectorConstReference<std::complex<T>, Sz>       \
00103   >,                  \
00104   Sz                  \
00105 >                 \
00106 NAME(const Vector<std::complex<T>, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;
00107 
00108 TVMET_DECLARE_MACRO(real)
00109 TVMET_DECLARE_MACRO(imag)
00110 TVMET_DECLARE_MACRO(arg)
00111 TVMET_DECLARE_MACRO(norm)
00112 TVMET_DECLARE_MACRO(conj)
00113 
00114 #undef TVMET_DECLARE_MACRO
00115 
00116 #endif // defined(TVMET_HAVE_COMPLEX)
00117 
00118 
00119 /*********************************************************
00120  * PART II: IMPLEMENTATION
00121  *********************************************************/
00122 
00123 
00124 /*
00125  * unary_function(Vector<T, Sz>)
00126  */
00127 #define TVMET_IMPLEMENT_MACRO(NAME)         \
00128 template<class T, std::size_t Sz>         \
00129 inline                  \
00130 XprVector<                \
00131   XprUnOp<                \
00132     Fcnl_##NAME<T>,             \
00133     VectorConstReference<T, Sz>           \
00134   >,                  \
00135   Sz                  \
00136 >                 \
00137 NAME(const Vector<T, Sz>& rhs) {          \
00138   typedef XprUnOp<              \
00139       Fcnl_##NAME<T>,             \
00140       VectorConstReference<T, Sz>         \
00141     >               expr_type;  \
00142     return XprVector<expr_type, Sz>(expr_type(rhs.const_ref()));  \
00143 }
00144 
00145 TVMET_IMPLEMENT_MACRO(abs)
00146 TVMET_IMPLEMENT_MACRO(cbrt)
00147 TVMET_IMPLEMENT_MACRO(ceil)
00148 TVMET_IMPLEMENT_MACRO(floor)
00149 TVMET_IMPLEMENT_MACRO(rint)
00150 TVMET_IMPLEMENT_MACRO(sin)
00151 TVMET_IMPLEMENT_MACRO(cos)
00152 TVMET_IMPLEMENT_MACRO(tan)
00153 TVMET_IMPLEMENT_MACRO(sinh)
00154 TVMET_IMPLEMENT_MACRO(cosh)
00155 TVMET_IMPLEMENT_MACRO(tanh)
00156 TVMET_IMPLEMENT_MACRO(asin)
00157 TVMET_IMPLEMENT_MACRO(acos)
00158 TVMET_IMPLEMENT_MACRO(atan)
00159 TVMET_IMPLEMENT_MACRO(exp)
00160 TVMET_IMPLEMENT_MACRO(log)
00161 TVMET_IMPLEMENT_MACRO(log10)
00162 TVMET_IMPLEMENT_MACRO(sqrt)
00163 
00164 #if defined(TVMET_HAVE_IEEE_MATH)
00165 TVMET_IMPLEMENT_MACRO(asinh)
00166 TVMET_IMPLEMENT_MACRO(acosh)
00167 TVMET_IMPLEMENT_MACRO(atanh)
00168 TVMET_IMPLEMENT_MACRO(expm1)
00169 TVMET_IMPLEMENT_MACRO(log1p)
00170 TVMET_IMPLEMENT_MACRO(erf)
00171 TVMET_IMPLEMENT_MACRO(erfc)
00172 TVMET_IMPLEMENT_MACRO(j0)
00173 TVMET_IMPLEMENT_MACRO(j1)
00174 TVMET_IMPLEMENT_MACRO(y0)
00175 TVMET_IMPLEMENT_MACRO(y1)
00176 TVMET_IMPLEMENT_MACRO(lgamma)
00178 #if !defined(TVMET_NO_IEEE_MATH_ISNAN)
00179 TVMET_IMPLEMENT_MACRO(isnan)
00180 #endif
00181 #if !defined(TVMET_NO_IEEE_MATH_ISINF)
00182 TVMET_IMPLEMENT_MACRO(isinf)
00183 #endif
00184 TVMET_IMPLEMENT_MACRO(finite)
00185 #endif // defined(TVMET_HAVE_IEEE_MATH)
00186 
00187 #undef TVMET_IMPLEMENT_MACRO
00188 
00189 
00190 /*
00191  * unary_function(Vector<std::complex<T>, Sz>)
00192  */
00193 #if defined(TVMET_HAVE_COMPLEX)
00194 #define TVMET_IMPLEMENT_MACRO(NAME)         \
00195 template<class T, std::size_t Sz>         \
00196 inline                  \
00197 XprVector<                \
00198   XprUnOp<                \
00199     Fcnl_##NAME< std::complex<T> >,         \
00200     VectorConstReference<std::complex<T>, Sz>       \
00201   >,                  \
00202   Sz                  \
00203 >                 \
00204 NAME(const Vector<std::complex<T>, Sz>& rhs) {        \
00205   typedef XprUnOp<              \
00206       Fcnl_##NAME< std::complex<T> >,         \
00207       VectorConstReference<std::complex<T>, Sz>       \
00208     >               expr_type;  \
00209     return XprVector<expr_type, Sz>(expr_type(rhs.const_ref()));  \
00210 }
00211 
00212 TVMET_IMPLEMENT_MACRO(real)
00213 TVMET_IMPLEMENT_MACRO(imag)
00214 TVMET_IMPLEMENT_MACRO(arg)
00215 TVMET_IMPLEMENT_MACRO(norm)
00216 TVMET_IMPLEMENT_MACRO(conj)
00217 
00218 #undef TVMET_IMPLEMENT_MACRO
00219 
00220 #endif // defined(TVMET_HAVE_COMPLEX)
00221 
00222 
00223 } // namespace tvmet
00224 
00225 #endif // TVMET_VECTOR_UNARY_FUNCTIONS_H
00226 
00227 // Local Variables:
00228 // mode:C++
00229 // tab-width:8
00230 // End:

Author: