ICRS Eurobot 2013
Dependencies: mbed mbed-rtos Servo QEI
tvmet/UnaryFunctionals.h@15:9c5aaeda36dc, 2013-04-06 (annotated)
- Committer:
- madcowswe
- Date:
- Sat Apr 06 20:57:54 2013 +0000
- Revision:
- 15:9c5aaeda36dc
Encoders fairly tuned, still has random noise in it
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
madcowswe | 15:9c5aaeda36dc | 1 | /* |
madcowswe | 15:9c5aaeda36dc | 2 | * Tiny Vector Matrix Library |
madcowswe | 15:9c5aaeda36dc | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
madcowswe | 15:9c5aaeda36dc | 4 | * |
madcowswe | 15:9c5aaeda36dc | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
madcowswe | 15:9c5aaeda36dc | 6 | * |
madcowswe | 15:9c5aaeda36dc | 7 | * This library is free software; you can redistribute it and/or |
madcowswe | 15:9c5aaeda36dc | 8 | * modify it under the terms of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 9 | * License as published by the Free Software Foundation; either |
madcowswe | 15:9c5aaeda36dc | 10 | * version 2.1 of the License, or (at your option) any later version. |
madcowswe | 15:9c5aaeda36dc | 11 | * |
madcowswe | 15:9c5aaeda36dc | 12 | * This library is distributed in the hope that it will be useful, |
madcowswe | 15:9c5aaeda36dc | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
madcowswe | 15:9c5aaeda36dc | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
madcowswe | 15:9c5aaeda36dc | 15 | * Lesser General Public License for more details. |
madcowswe | 15:9c5aaeda36dc | 16 | * |
madcowswe | 15:9c5aaeda36dc | 17 | * You should have received a copy of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 18 | * License along with this library; if not, write to the Free Software |
madcowswe | 15:9c5aaeda36dc | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
madcowswe | 15:9c5aaeda36dc | 20 | * |
madcowswe | 15:9c5aaeda36dc | 21 | * $Id: UnaryFunctionals.h,v 1.24 2007-06-23 15:58:58 opetzold Exp $ |
madcowswe | 15:9c5aaeda36dc | 22 | */ |
madcowswe | 15:9c5aaeda36dc | 23 | |
madcowswe | 15:9c5aaeda36dc | 24 | #ifndef TVMET_UNARY_FUNCTIONAL_H |
madcowswe | 15:9c5aaeda36dc | 25 | #define TVMET_UNARY_FUNCTIONAL_H |
madcowswe | 15:9c5aaeda36dc | 26 | |
madcowswe | 15:9c5aaeda36dc | 27 | namespace tvmet { |
madcowswe | 15:9c5aaeda36dc | 28 | |
madcowswe | 15:9c5aaeda36dc | 29 | /** \class Fcnl_compl UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 30 | /** \class Fcnl_neg UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 31 | /** \class Fcnl_not UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 32 | #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ |
madcowswe | 15:9c5aaeda36dc | 33 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 34 | struct Fcnl_##NAME : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 35 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 36 | \ |
madcowswe | 15:9c5aaeda36dc | 37 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 38 | value_type apply_on(value_type rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 39 | return OP rhs; \ |
madcowswe | 15:9c5aaeda36dc | 40 | } \ |
madcowswe | 15:9c5aaeda36dc | 41 | \ |
madcowswe | 15:9c5aaeda36dc | 42 | static \ |
madcowswe | 15:9c5aaeda36dc | 43 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 44 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 45 | << typeid(T).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 46 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 47 | } \ |
madcowswe | 15:9c5aaeda36dc | 48 | }; |
madcowswe | 15:9c5aaeda36dc | 49 | |
madcowswe | 15:9c5aaeda36dc | 50 | TVMET_IMPLEMENT_MACRO(compl, ~) |
madcowswe | 15:9c5aaeda36dc | 51 | TVMET_IMPLEMENT_MACRO(neg, -) |
madcowswe | 15:9c5aaeda36dc | 52 | TVMET_IMPLEMENT_MACRO(not, !) |
madcowswe | 15:9c5aaeda36dc | 53 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 54 | |
madcowswe | 15:9c5aaeda36dc | 55 | |
madcowswe | 15:9c5aaeda36dc | 56 | /** \class Fcnl_abs UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 57 | /** \class Fcnl_ceil UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 58 | /** \class Fcnl_floor UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 59 | /** \class Fcnl_sin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 60 | /** \class Fcnl_cos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 61 | /** \class Fcnl_tan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 62 | /** \class Fcnl_sinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 63 | /** \class Fcnl_cosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 64 | /** \class Fcnl_tanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 65 | /** \class Fcnl_asin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 66 | /** \class Fcnl_acos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 67 | /** \class Fcnl_atan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 68 | /** \class Fcnl_exp UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 69 | /** \class Fcnl_log UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 70 | /** \class Fcnl_log10 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 71 | /** \class Fcnl_sqrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 72 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 15:9c5aaeda36dc | 73 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 74 | struct Fcnl_##NAME : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 75 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 76 | \ |
madcowswe | 15:9c5aaeda36dc | 77 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 78 | value_type apply_on(value_type rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 79 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 80 | } \ |
madcowswe | 15:9c5aaeda36dc | 81 | \ |
madcowswe | 15:9c5aaeda36dc | 82 | static \ |
madcowswe | 15:9c5aaeda36dc | 83 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 84 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 85 | << typeid(value_type).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 86 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 87 | } \ |
madcowswe | 15:9c5aaeda36dc | 88 | }; |
madcowswe | 15:9c5aaeda36dc | 89 | |
madcowswe | 15:9c5aaeda36dc | 90 | TVMET_IMPLEMENT_MACRO(abs) // specialized later, see below |
madcowswe | 15:9c5aaeda36dc | 91 | TVMET_IMPLEMENT_MACRO(ceil) |
madcowswe | 15:9c5aaeda36dc | 92 | TVMET_IMPLEMENT_MACRO(floor) |
madcowswe | 15:9c5aaeda36dc | 93 | TVMET_IMPLEMENT_MACRO(sin) |
madcowswe | 15:9c5aaeda36dc | 94 | TVMET_IMPLEMENT_MACRO(cos) |
madcowswe | 15:9c5aaeda36dc | 95 | TVMET_IMPLEMENT_MACRO(tan) |
madcowswe | 15:9c5aaeda36dc | 96 | TVMET_IMPLEMENT_MACRO(sinh) |
madcowswe | 15:9c5aaeda36dc | 97 | TVMET_IMPLEMENT_MACRO(cosh) |
madcowswe | 15:9c5aaeda36dc | 98 | TVMET_IMPLEMENT_MACRO(tanh) |
madcowswe | 15:9c5aaeda36dc | 99 | TVMET_IMPLEMENT_MACRO(asin) |
madcowswe | 15:9c5aaeda36dc | 100 | TVMET_IMPLEMENT_MACRO(acos) |
madcowswe | 15:9c5aaeda36dc | 101 | TVMET_IMPLEMENT_MACRO(atan) |
madcowswe | 15:9c5aaeda36dc | 102 | TVMET_IMPLEMENT_MACRO(exp) |
madcowswe | 15:9c5aaeda36dc | 103 | TVMET_IMPLEMENT_MACRO(log) |
madcowswe | 15:9c5aaeda36dc | 104 | TVMET_IMPLEMENT_MACRO(log10) |
madcowswe | 15:9c5aaeda36dc | 105 | TVMET_IMPLEMENT_MACRO(sqrt) |
madcowswe | 15:9c5aaeda36dc | 106 | |
madcowswe | 15:9c5aaeda36dc | 107 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 108 | |
madcowswe | 15:9c5aaeda36dc | 109 | |
madcowswe | 15:9c5aaeda36dc | 110 | /** \class Fcnl_cbrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 111 | /** \class Fcnl_rint UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 112 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 15:9c5aaeda36dc | 113 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 114 | struct Fcnl_##NAME : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 115 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 116 | \ |
madcowswe | 15:9c5aaeda36dc | 117 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 118 | value_type apply_on(value_type rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 119 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 120 | } \ |
madcowswe | 15:9c5aaeda36dc | 121 | \ |
madcowswe | 15:9c5aaeda36dc | 122 | static \ |
madcowswe | 15:9c5aaeda36dc | 123 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 124 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 125 | << typeid(value_type).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 126 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 127 | } \ |
madcowswe | 15:9c5aaeda36dc | 128 | }; |
madcowswe | 15:9c5aaeda36dc | 129 | |
madcowswe | 15:9c5aaeda36dc | 130 | TVMET_IMPLEMENT_MACRO(cbrt) |
madcowswe | 15:9c5aaeda36dc | 131 | TVMET_IMPLEMENT_MACRO(rint) |
madcowswe | 15:9c5aaeda36dc | 132 | |
madcowswe | 15:9c5aaeda36dc | 133 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 134 | |
madcowswe | 15:9c5aaeda36dc | 135 | |
madcowswe | 15:9c5aaeda36dc | 136 | #if defined(TVMET_HAVE_IEEE_MATH) |
madcowswe | 15:9c5aaeda36dc | 137 | |
madcowswe | 15:9c5aaeda36dc | 138 | /** \class Fcnl_asinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 139 | /** \class Fcnl_acosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 140 | /** \class Fcnl_atanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 141 | /** \class Fcnl_expm1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 142 | /** \class Fcnl_log1p UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 143 | /** \class Fcnl_erf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 144 | /** \class Fcnl_erfc UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 145 | /** \class Fcnl_j0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 146 | /** \class Fcnl_j1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 147 | /** \class Fcnl_y0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 148 | /** \class Fcnl_y1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 149 | /** \class Fcnl_lgamma UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 150 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 15:9c5aaeda36dc | 151 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 152 | struct Fcnl_##NAME : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 153 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 154 | \ |
madcowswe | 15:9c5aaeda36dc | 155 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 156 | value_type apply_on(value_type rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 157 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 158 | } \ |
madcowswe | 15:9c5aaeda36dc | 159 | \ |
madcowswe | 15:9c5aaeda36dc | 160 | static \ |
madcowswe | 15:9c5aaeda36dc | 161 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 162 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 163 | << typeid(value_type).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 164 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 165 | } \ |
madcowswe | 15:9c5aaeda36dc | 166 | }; |
madcowswe | 15:9c5aaeda36dc | 167 | |
madcowswe | 15:9c5aaeda36dc | 168 | TVMET_IMPLEMENT_MACRO(asinh) |
madcowswe | 15:9c5aaeda36dc | 169 | TVMET_IMPLEMENT_MACRO(acosh) |
madcowswe | 15:9c5aaeda36dc | 170 | TVMET_IMPLEMENT_MACRO(atanh) |
madcowswe | 15:9c5aaeda36dc | 171 | TVMET_IMPLEMENT_MACRO(expm1) |
madcowswe | 15:9c5aaeda36dc | 172 | TVMET_IMPLEMENT_MACRO(log1p) |
madcowswe | 15:9c5aaeda36dc | 173 | TVMET_IMPLEMENT_MACRO(erf) |
madcowswe | 15:9c5aaeda36dc | 174 | TVMET_IMPLEMENT_MACRO(erfc) |
madcowswe | 15:9c5aaeda36dc | 175 | TVMET_IMPLEMENT_MACRO(j0) |
madcowswe | 15:9c5aaeda36dc | 176 | TVMET_IMPLEMENT_MACRO(j1) |
madcowswe | 15:9c5aaeda36dc | 177 | TVMET_IMPLEMENT_MACRO(y0) |
madcowswe | 15:9c5aaeda36dc | 178 | TVMET_IMPLEMENT_MACRO(y1) |
madcowswe | 15:9c5aaeda36dc | 179 | TVMET_IMPLEMENT_MACRO(lgamma) |
madcowswe | 15:9c5aaeda36dc | 180 | |
madcowswe | 15:9c5aaeda36dc | 181 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 182 | |
madcowswe | 15:9c5aaeda36dc | 183 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
madcowswe | 15:9c5aaeda36dc | 184 | |
madcowswe | 15:9c5aaeda36dc | 185 | |
madcowswe | 15:9c5aaeda36dc | 186 | /** \class Fcnl_abs<long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 187 | /** \class Fcnl_abs<long long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 188 | /** \class Fcnl_abs<float> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 189 | /** \class Fcnl_abs<double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 190 | /** \class Fcnl_abs<long double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 191 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
madcowswe | 15:9c5aaeda36dc | 192 | template <class T> struct Fcnl_##NAME; \ |
madcowswe | 15:9c5aaeda36dc | 193 | template <> \ |
madcowswe | 15:9c5aaeda36dc | 194 | struct Fcnl_##NAME< POD > : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 195 | typedef POD value_type; \ |
madcowswe | 15:9c5aaeda36dc | 196 | \ |
madcowswe | 15:9c5aaeda36dc | 197 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 198 | value_type apply_on(value_type rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 199 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 200 | } \ |
madcowswe | 15:9c5aaeda36dc | 201 | \ |
madcowswe | 15:9c5aaeda36dc | 202 | static \ |
madcowswe | 15:9c5aaeda36dc | 203 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 204 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 205 | << typeid(value_type).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 206 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 207 | } \ |
madcowswe | 15:9c5aaeda36dc | 208 | }; |
madcowswe | 15:9c5aaeda36dc | 209 | |
madcowswe | 15:9c5aaeda36dc | 210 | TVMET_IMPLEMENT_MACRO(labs, long int) |
madcowswe | 15:9c5aaeda36dc | 211 | |
madcowswe | 15:9c5aaeda36dc | 212 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 213 | TVMET_IMPLEMENT_MACRO(labs, long long int) |
madcowswe | 15:9c5aaeda36dc | 214 | #endif |
madcowswe | 15:9c5aaeda36dc | 215 | |
madcowswe | 15:9c5aaeda36dc | 216 | TVMET_IMPLEMENT_MACRO(fabs, float) |
madcowswe | 15:9c5aaeda36dc | 217 | TVMET_IMPLEMENT_MACRO(fabs, double) |
madcowswe | 15:9c5aaeda36dc | 218 | |
madcowswe | 15:9c5aaeda36dc | 219 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 220 | TVMET_IMPLEMENT_MACRO(fabs, long double) |
madcowswe | 15:9c5aaeda36dc | 221 | #endif |
madcowswe | 15:9c5aaeda36dc | 222 | |
madcowswe | 15:9c5aaeda36dc | 223 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 224 | |
madcowswe | 15:9c5aaeda36dc | 225 | |
madcowswe | 15:9c5aaeda36dc | 226 | /* |
madcowswe | 15:9c5aaeda36dc | 227 | * complex support |
madcowswe | 15:9c5aaeda36dc | 228 | */ |
madcowswe | 15:9c5aaeda36dc | 229 | |
madcowswe | 15:9c5aaeda36dc | 230 | #if defined(TVMET_HAVE_COMPLEX) |
madcowswe | 15:9c5aaeda36dc | 231 | /** |
madcowswe | 15:9c5aaeda36dc | 232 | * \class Fcnl_abs< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" |
madcowswe | 15:9c5aaeda36dc | 233 | */ |
madcowswe | 15:9c5aaeda36dc | 234 | template <class T> |
madcowswe | 15:9c5aaeda36dc | 235 | struct Fcnl_abs< std::complex<T> > : public UnaryFunctional { |
madcowswe | 15:9c5aaeda36dc | 236 | typedef T value_type; |
madcowswe | 15:9c5aaeda36dc | 237 | |
madcowswe | 15:9c5aaeda36dc | 238 | static inline |
madcowswe | 15:9c5aaeda36dc | 239 | value_type apply_on(const std::complex<T>& rhs) { |
madcowswe | 15:9c5aaeda36dc | 240 | return std::abs(rhs); |
madcowswe | 15:9c5aaeda36dc | 241 | } |
madcowswe | 15:9c5aaeda36dc | 242 | |
madcowswe | 15:9c5aaeda36dc | 243 | static |
madcowswe | 15:9c5aaeda36dc | 244 | void print_xpr(std::ostream& os, std::size_t l=0) { |
madcowswe | 15:9c5aaeda36dc | 245 | os << IndentLevel(l) << "Fcnl_abs<T=" |
madcowswe | 15:9c5aaeda36dc | 246 | << typeid(std::complex<T>).name() << ">," |
madcowswe | 15:9c5aaeda36dc | 247 | << std::endl; |
madcowswe | 15:9c5aaeda36dc | 248 | } |
madcowswe | 15:9c5aaeda36dc | 249 | }; |
madcowswe | 15:9c5aaeda36dc | 250 | |
madcowswe | 15:9c5aaeda36dc | 251 | |
madcowswe | 15:9c5aaeda36dc | 252 | /** |
madcowswe | 15:9c5aaeda36dc | 253 | * \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" |
madcowswe | 15:9c5aaeda36dc | 254 | * \brief %Functional for conj. |
madcowswe | 15:9c5aaeda36dc | 255 | */ |
madcowswe | 15:9c5aaeda36dc | 256 | template <class T> struct Fcnl_conj : public UnaryFunctional { }; |
madcowswe | 15:9c5aaeda36dc | 257 | |
madcowswe | 15:9c5aaeda36dc | 258 | |
madcowswe | 15:9c5aaeda36dc | 259 | /** \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 260 | template <class T> |
madcowswe | 15:9c5aaeda36dc | 261 | struct Fcnl_conj< std::complex<T> > : public UnaryFunctional { |
madcowswe | 15:9c5aaeda36dc | 262 | typedef std::complex<T> value_type; |
madcowswe | 15:9c5aaeda36dc | 263 | |
madcowswe | 15:9c5aaeda36dc | 264 | static inline |
madcowswe | 15:9c5aaeda36dc | 265 | value_type apply_on(const std::complex<T>& rhs) { |
madcowswe | 15:9c5aaeda36dc | 266 | return std::conj(rhs); |
madcowswe | 15:9c5aaeda36dc | 267 | } |
madcowswe | 15:9c5aaeda36dc | 268 | |
madcowswe | 15:9c5aaeda36dc | 269 | static |
madcowswe | 15:9c5aaeda36dc | 270 | void print_xpr(std::ostream& os, std::size_t l=0) { |
madcowswe | 15:9c5aaeda36dc | 271 | os << IndentLevel(l) << "Fcnl_conj<T=" |
madcowswe | 15:9c5aaeda36dc | 272 | << typeid(std::complex<T>).name() << ">," |
madcowswe | 15:9c5aaeda36dc | 273 | << std::endl; |
madcowswe | 15:9c5aaeda36dc | 274 | } |
madcowswe | 15:9c5aaeda36dc | 275 | }; |
madcowswe | 15:9c5aaeda36dc | 276 | |
madcowswe | 15:9c5aaeda36dc | 277 | |
madcowswe | 15:9c5aaeda36dc | 278 | /** \class Fcnl_real< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 279 | /** \class Fcnl_imag< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 280 | /** \class Fcnl_arg< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 281 | /** \class Fcnl_norm< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 282 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 15:9c5aaeda36dc | 283 | template <class T> struct Fcnl_##NAME; \ |
madcowswe | 15:9c5aaeda36dc | 284 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 285 | struct Fcnl_##NAME< std::complex<T> > : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 286 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 287 | \ |
madcowswe | 15:9c5aaeda36dc | 288 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 289 | value_type apply_on(const std::complex<T>& rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 290 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 291 | } \ |
madcowswe | 15:9c5aaeda36dc | 292 | \ |
madcowswe | 15:9c5aaeda36dc | 293 | static \ |
madcowswe | 15:9c5aaeda36dc | 294 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 295 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 296 | << typeid(std::complex<T>).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 297 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 298 | } \ |
madcowswe | 15:9c5aaeda36dc | 299 | }; |
madcowswe | 15:9c5aaeda36dc | 300 | |
madcowswe | 15:9c5aaeda36dc | 301 | TVMET_IMPLEMENT_MACRO(real) |
madcowswe | 15:9c5aaeda36dc | 302 | TVMET_IMPLEMENT_MACRO(imag) |
madcowswe | 15:9c5aaeda36dc | 303 | TVMET_IMPLEMENT_MACRO(arg) |
madcowswe | 15:9c5aaeda36dc | 304 | TVMET_IMPLEMENT_MACRO(norm) |
madcowswe | 15:9c5aaeda36dc | 305 | |
madcowswe | 15:9c5aaeda36dc | 306 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 307 | |
madcowswe | 15:9c5aaeda36dc | 308 | #endif // defined(TVMET_HAVE_COMPLEX) |
madcowswe | 15:9c5aaeda36dc | 309 | |
madcowswe | 15:9c5aaeda36dc | 310 | |
madcowswe | 15:9c5aaeda36dc | 311 | #if defined(TVMET_HAVE_IEEE_MATH) |
madcowswe | 15:9c5aaeda36dc | 312 | |
madcowswe | 15:9c5aaeda36dc | 313 | /** \class Fcnl_isnan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 314 | /** \class Fcnl_isinf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 315 | /** \class Fcnl_finite UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
madcowswe | 15:9c5aaeda36dc | 316 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
madcowswe | 15:9c5aaeda36dc | 317 | template <class T> \ |
madcowswe | 15:9c5aaeda36dc | 318 | struct Fcnl_##NAME : public UnaryFunctional { \ |
madcowswe | 15:9c5aaeda36dc | 319 | typedef T value_type; \ |
madcowswe | 15:9c5aaeda36dc | 320 | \ |
madcowswe | 15:9c5aaeda36dc | 321 | static inline \ |
madcowswe | 15:9c5aaeda36dc | 322 | POD apply_on(T rhs) { \ |
madcowswe | 15:9c5aaeda36dc | 323 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
madcowswe | 15:9c5aaeda36dc | 324 | } \ |
madcowswe | 15:9c5aaeda36dc | 325 | \ |
madcowswe | 15:9c5aaeda36dc | 326 | static \ |
madcowswe | 15:9c5aaeda36dc | 327 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
madcowswe | 15:9c5aaeda36dc | 328 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
madcowswe | 15:9c5aaeda36dc | 329 | << typeid(POD).name() << ">," \ |
madcowswe | 15:9c5aaeda36dc | 330 | << std::endl; \ |
madcowswe | 15:9c5aaeda36dc | 331 | } \ |
madcowswe | 15:9c5aaeda36dc | 332 | }; |
madcowswe | 15:9c5aaeda36dc | 333 | |
madcowswe | 15:9c5aaeda36dc | 334 | TVMET_IMPLEMENT_MACRO(isnan, int) |
madcowswe | 15:9c5aaeda36dc | 335 | TVMET_IMPLEMENT_MACRO(isinf, int) |
madcowswe | 15:9c5aaeda36dc | 336 | TVMET_IMPLEMENT_MACRO(finite, int) |
madcowswe | 15:9c5aaeda36dc | 337 | |
madcowswe | 15:9c5aaeda36dc | 338 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 15:9c5aaeda36dc | 339 | |
madcowswe | 15:9c5aaeda36dc | 340 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
madcowswe | 15:9c5aaeda36dc | 341 | |
madcowswe | 15:9c5aaeda36dc | 342 | } // namespace tvmet |
madcowswe | 15:9c5aaeda36dc | 343 | |
madcowswe | 15:9c5aaeda36dc | 344 | #endif // TVMET_UNARY_FUNCTIONAL_H |
madcowswe | 15:9c5aaeda36dc | 345 | |
madcowswe | 15:9c5aaeda36dc | 346 | // Local Variables: |
madcowswe | 15:9c5aaeda36dc | 347 | // mode:C++ |
madcowswe | 15:9c5aaeda36dc | 348 | // tab-width:8 |
madcowswe | 15:9c5aaeda36dc | 349 | // End: |