00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef TVMET_UNARY_FUNCTIONAL_H
00025 #define TVMET_UNARY_FUNCTIONAL_H
00026
00027 namespace tvmet {
00028
00032 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
00033 template <class T> \
00034 struct Fcnl_##NAME : public UnaryFunctional { \
00035 typedef T value_type; \
00036 \
00037 static inline \
00038 value_type apply_on(value_type rhs) { \
00039 return OP rhs; \
00040 } \
00041 \
00042 static \
00043 void print_xpr(std::ostream& os, std::size_t l=0) { \
00044 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00045 << typeid(T).name() << ">," \
00046 << std::endl; \
00047 } \
00048 };
00049
00050 TVMET_IMPLEMENT_MACRO(compl, ~)
00051 TVMET_IMPLEMENT_MACRO(neg, -)
00052 TVMET_IMPLEMENT_MACRO(not, !)
00053 #undef TVMET_IMPLEMENT_MACRO
00054
00055
00072 #define TVMET_IMPLEMENT_MACRO(NAME) \
00073 template <class T> \
00074 struct Fcnl_##NAME : public UnaryFunctional { \
00075 typedef T value_type; \
00076 \
00077 static inline \
00078 value_type apply_on(value_type rhs) { \
00079 return TVMET_STD_SCOPE(NAME)(rhs); \
00080 } \
00081 \
00082 static \
00083 void print_xpr(std::ostream& os, std::size_t l=0) { \
00084 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00085 << typeid(value_type).name() << ">," \
00086 << std::endl; \
00087 } \
00088 };
00089
00090 TVMET_IMPLEMENT_MACRO(abs)
00091 TVMET_IMPLEMENT_MACRO(ceil)
00092 TVMET_IMPLEMENT_MACRO(floor)
00093 TVMET_IMPLEMENT_MACRO(sin)
00094 TVMET_IMPLEMENT_MACRO(cos)
00095 TVMET_IMPLEMENT_MACRO(tan)
00096 TVMET_IMPLEMENT_MACRO(sinh)
00097 TVMET_IMPLEMENT_MACRO(cosh)
00098 TVMET_IMPLEMENT_MACRO(tanh)
00099 TVMET_IMPLEMENT_MACRO(asin)
00100 TVMET_IMPLEMENT_MACRO(acos)
00101 TVMET_IMPLEMENT_MACRO(atan)
00102 TVMET_IMPLEMENT_MACRO(exp)
00103 TVMET_IMPLEMENT_MACRO(log)
00104 TVMET_IMPLEMENT_MACRO(log10)
00105 TVMET_IMPLEMENT_MACRO(sqrt)
00106
00107 #undef TVMET_IMPLEMENT_MACRO
00108
00109
00112 #define TVMET_IMPLEMENT_MACRO(NAME) \
00113 template <class T> \
00114 struct Fcnl_##NAME : public UnaryFunctional { \
00115 typedef T value_type; \
00116 \
00117 static inline \
00118 value_type apply_on(value_type rhs) { \
00119 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \
00120 } \
00121 \
00122 static \
00123 void print_xpr(std::ostream& os, std::size_t l=0) { \
00124 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00125 << typeid(value_type).name() << ">," \
00126 << std::endl; \
00127 } \
00128 };
00129
00130 TVMET_IMPLEMENT_MACRO(cbrt)
00131 TVMET_IMPLEMENT_MACRO(rint)
00132
00133 #undef TVMET_IMPLEMENT_MACRO
00134
00135
00136 #if defined(TVMET_HAVE_IEEE_MATH)
00137
00150 #define TVMET_IMPLEMENT_MACRO(NAME) \
00151 template <class T> \
00152 struct Fcnl_##NAME : public UnaryFunctional { \
00153 typedef T value_type; \
00154 \
00155 static inline \
00156 value_type apply_on(value_type rhs) { \
00157 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \
00158 } \
00159 \
00160 static \
00161 void print_xpr(std::ostream& os, std::size_t l=0) { \
00162 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00163 << typeid(value_type).name() << ">," \
00164 << std::endl; \
00165 } \
00166 };
00167
00168 TVMET_IMPLEMENT_MACRO(asinh)
00169 TVMET_IMPLEMENT_MACRO(acosh)
00170 TVMET_IMPLEMENT_MACRO(atanh)
00171 TVMET_IMPLEMENT_MACRO(expm1)
00172 TVMET_IMPLEMENT_MACRO(log1p)
00173 TVMET_IMPLEMENT_MACRO(erf)
00174 TVMET_IMPLEMENT_MACRO(erfc)
00175 TVMET_IMPLEMENT_MACRO(j0)
00176 TVMET_IMPLEMENT_MACRO(j1)
00177 TVMET_IMPLEMENT_MACRO(y0)
00178 TVMET_IMPLEMENT_MACRO(y1)
00179 TVMET_IMPLEMENT_MACRO(lgamma)
00180
00181 #undef TVMET_IMPLEMENT_MACRO
00182
00183 #endif // defined(TVMET_HAVE_IEEE_MATH)
00184
00185
00191 #define TVMET_IMPLEMENT_MACRO(NAME, POD) \
00192 template <class T> struct Fcnl_##NAME; \
00193 template <> \
00194 struct Fcnl_##NAME< POD > : public UnaryFunctional { \
00195 typedef POD value_type; \
00196 \
00197 static inline \
00198 value_type apply_on(value_type rhs) { \
00199 return TVMET_STD_SCOPE(NAME)(rhs); \
00200 } \
00201 \
00202 static \
00203 void print_xpr(std::ostream& os, std::size_t l=0) { \
00204 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00205 << typeid(value_type).name() << ">," \
00206 << std::endl; \
00207 } \
00208 };
00209
00210 TVMET_IMPLEMENT_MACRO(labs, long int)
00211
00212 #if defined(TVMET_HAVE_LONG_LONG)
00213 TVMET_IMPLEMENT_MACRO(labs, long long int)
00214 #endif
00215
00216 TVMET_IMPLEMENT_MACRO(fabs, float)
00217 TVMET_IMPLEMENT_MACRO(fabs, double)
00218
00219 #if defined(TVMET_HAVE_LONG_DOUBLE)
00220 TVMET_IMPLEMENT_MACRO(fabs, long double)
00221 #endif
00222
00223 #undef TVMET_IMPLEMENT_MACRO
00224
00225
00226
00227
00228
00229
00230 #if defined(TVMET_HAVE_COMPLEX)
00231
00234 template <class T>
00235 struct Fcnl_abs< std::complex<T> > : public UnaryFunctional {
00236 typedef T value_type;
00237
00238 static inline
00239 value_type apply_on(const std::complex<T>& rhs) {
00240 return std::abs(rhs);
00241 }
00242
00243 static
00244 void print_xpr(std::ostream& os, std::size_t l=0) {
00245 os << IndentLevel(l) << "Fcnl_abs<T="
00246 << typeid(std::complex<T>).name() << ">,"
00247 << std::endl;
00248 }
00249 };
00250
00251
00256 template <class T> struct Fcnl_conj : public UnaryFunctional { };
00257
00258
00260 template <class T>
00261 struct Fcnl_conj< std::complex<T> > : public UnaryFunctional {
00262 typedef std::complex<T> value_type;
00263
00264 static inline
00265 value_type apply_on(const std::complex<T>& rhs) {
00266 return std::conj(rhs);
00267 }
00268
00269 static
00270 void print_xpr(std::ostream& os, std::size_t l=0) {
00271 os << IndentLevel(l) << "Fcnl_conj<T="
00272 << typeid(std::complex<T>).name() << ">,"
00273 << std::endl;
00274 }
00275 };
00276
00277
00282 #define TVMET_IMPLEMENT_MACRO(NAME) \
00283 template <class T> struct Fcnl_##NAME; \
00284 template <class T> \
00285 struct Fcnl_##NAME< std::complex<T> > : public UnaryFunctional { \
00286 typedef T value_type; \
00287 \
00288 static inline \
00289 value_type apply_on(const std::complex<T>& rhs) { \
00290 return TVMET_STD_SCOPE(NAME)(rhs); \
00291 } \
00292 \
00293 static \
00294 void print_xpr(std::ostream& os, std::size_t l=0) { \
00295 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00296 << typeid(std::complex<T>).name() << ">," \
00297 << std::endl; \
00298 } \
00299 };
00300
00301 TVMET_IMPLEMENT_MACRO(real)
00302 TVMET_IMPLEMENT_MACRO(imag)
00303 TVMET_IMPLEMENT_MACRO(arg)
00304 TVMET_IMPLEMENT_MACRO(norm)
00305
00306 #undef TVMET_IMPLEMENT_MACRO
00307
00308 #endif // defined(TVMET_HAVE_COMPLEX)
00309
00310
00311 #if defined(TVMET_HAVE_IEEE_MATH)
00312
00316 #define TVMET_IMPLEMENT_MACRO(NAME, POD) \
00317 template <class T> \
00318 struct Fcnl_##NAME : public UnaryFunctional { \
00319 typedef T value_type; \
00320 \
00321 static inline \
00322 POD apply_on(T rhs) { \
00323 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \
00324 } \
00325 \
00326 static \
00327 void print_xpr(std::ostream& os, std::size_t l=0) { \
00328 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \
00329 << typeid(POD).name() << ">," \
00330 << std::endl; \
00331 } \
00332 };
00333
00334 TVMET_IMPLEMENT_MACRO(isnan, int)
00335 TVMET_IMPLEMENT_MACRO(isinf, int)
00336 TVMET_IMPLEMENT_MACRO(finite, int)
00337
00338 #undef TVMET_IMPLEMENT_MACRO
00339
00340 #endif // defined(TVMET_HAVE_IEEE_MATH)
00341
00342 }
00343
00344 #endif // TVMET_UNARY_FUNCTIONAL_H
00345
00346
00347
00348
00349