Colour sensors calibrated
Dependencies: mbed-rtos mbed Servo QEI
Fork of ICRSEurobot13 by
tvmet/NumericTraits.h@17:6263e90bf3ba, 2013-04-07 (annotated)
- Committer:
- madcowswe
- Date:
- Sun Apr 07 17:51:59 2013 +0000
- Revision:
- 17:6263e90bf3ba
- Parent:
- 15:9c5aaeda36dc
Still fixing init in kalman
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: NumericTraits.h,v 1.16 2007-06-23 15:58:58 opetzold Exp $ |
madcowswe | 15:9c5aaeda36dc | 22 | */ |
madcowswe | 15:9c5aaeda36dc | 23 | |
madcowswe | 15:9c5aaeda36dc | 24 | #ifndef TVMET_NUMERIC_TRAITS_H |
madcowswe | 15:9c5aaeda36dc | 25 | #define TVMET_NUMERIC_TRAITS_H |
madcowswe | 15:9c5aaeda36dc | 26 | |
madcowswe | 15:9c5aaeda36dc | 27 | #if defined(TVMET_HAVE_COMPLEX) |
madcowswe | 15:9c5aaeda36dc | 28 | # include <complex> |
madcowswe | 15:9c5aaeda36dc | 29 | #endif |
madcowswe | 15:9c5aaeda36dc | 30 | #include <cmath> |
madcowswe | 15:9c5aaeda36dc | 31 | #include <limits> |
madcowswe | 15:9c5aaeda36dc | 32 | |
madcowswe | 15:9c5aaeda36dc | 33 | #include <tvmet/CompileTimeError.h> |
madcowswe | 15:9c5aaeda36dc | 34 | |
madcowswe | 15:9c5aaeda36dc | 35 | |
madcowswe | 15:9c5aaeda36dc | 36 | namespace tvmet { |
madcowswe | 15:9c5aaeda36dc | 37 | |
madcowswe | 15:9c5aaeda36dc | 38 | |
madcowswe | 15:9c5aaeda36dc | 39 | /** |
madcowswe | 15:9c5aaeda36dc | 40 | * \class NumericTraits NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 41 | * \brief Traits for integral types for operations. |
madcowswe | 15:9c5aaeda36dc | 42 | * |
madcowswe | 15:9c5aaeda36dc | 43 | * For each type we have to specialize this traits. |
madcowswe | 15:9c5aaeda36dc | 44 | * |
madcowswe | 15:9c5aaeda36dc | 45 | * \note Keep in mind that the long types long long and long double doesn't |
madcowswe | 15:9c5aaeda36dc | 46 | * have traits. This is due to the sum_type. We can't give a guarantee |
madcowswe | 15:9c5aaeda36dc | 47 | * that there is a type of holding the sum. Therefore using this traits |
madcowswe | 15:9c5aaeda36dc | 48 | * is only safe if you have long long resp. long double types by |
madcowswe | 15:9c5aaeda36dc | 49 | * working on long ints and doubles. Otherwise you will get not expected |
madcowswe | 15:9c5aaeda36dc | 50 | * result for some circumstances. Anyway, you can use big integer/float |
madcowswe | 15:9c5aaeda36dc | 51 | * libraries and specialize the traits by your own. |
madcowswe | 15:9c5aaeda36dc | 52 | * |
madcowswe | 15:9c5aaeda36dc | 53 | * \todo The abs function of complex<non_float_type> can have an |
madcowswe | 15:9c5aaeda36dc | 54 | * overrun due to numeric computation. Solve it (someone |
madcowswe | 15:9c5aaeda36dc | 55 | * using value_type=long here?) |
madcowswe | 15:9c5aaeda36dc | 56 | */ |
madcowswe | 15:9c5aaeda36dc | 57 | template<class T> |
madcowswe | 15:9c5aaeda36dc | 58 | struct NumericTraits { |
madcowswe | 15:9c5aaeda36dc | 59 | typedef T base_type; |
madcowswe | 15:9c5aaeda36dc | 60 | typedef T value_type; |
madcowswe | 15:9c5aaeda36dc | 61 | typedef value_type sum_type; |
madcowswe | 15:9c5aaeda36dc | 62 | typedef value_type diff_type; |
madcowswe | 15:9c5aaeda36dc | 63 | typedef value_type float_type; |
madcowswe | 15:9c5aaeda36dc | 64 | typedef value_type signed_type; |
madcowswe | 15:9c5aaeda36dc | 65 | |
madcowswe | 15:9c5aaeda36dc | 66 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 67 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 68 | |
madcowswe | 15:9c5aaeda36dc | 69 | static inline |
madcowswe | 15:9c5aaeda36dc | 70 | base_type real(argument_type x); |
madcowswe | 15:9c5aaeda36dc | 71 | |
madcowswe | 15:9c5aaeda36dc | 72 | static inline |
madcowswe | 15:9c5aaeda36dc | 73 | base_type imag(argument_type x); |
madcowswe | 15:9c5aaeda36dc | 74 | |
madcowswe | 15:9c5aaeda36dc | 75 | static inline |
madcowswe | 15:9c5aaeda36dc | 76 | value_type conj(argument_type x); |
madcowswe | 15:9c5aaeda36dc | 77 | |
madcowswe | 15:9c5aaeda36dc | 78 | static inline |
madcowswe | 15:9c5aaeda36dc | 79 | base_type abs(argument_type x); |
madcowswe | 15:9c5aaeda36dc | 80 | |
madcowswe | 15:9c5aaeda36dc | 81 | static inline |
madcowswe | 15:9c5aaeda36dc | 82 | value_type sqrt(argument_type x); |
madcowswe | 15:9c5aaeda36dc | 83 | |
madcowswe | 15:9c5aaeda36dc | 84 | static inline |
madcowswe | 15:9c5aaeda36dc | 85 | base_type norm_1(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 86 | return NumericTraits<base_type>::abs(traits_type::real(x)) |
madcowswe | 15:9c5aaeda36dc | 87 | + NumericTraits<base_type>::abs(traits_type::imag(x)); |
madcowswe | 15:9c5aaeda36dc | 88 | } |
madcowswe | 15:9c5aaeda36dc | 89 | |
madcowswe | 15:9c5aaeda36dc | 90 | static inline |
madcowswe | 15:9c5aaeda36dc | 91 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 92 | |
madcowswe | 15:9c5aaeda36dc | 93 | static inline |
madcowswe | 15:9c5aaeda36dc | 94 | base_type norm_inf(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 95 | return std::max(NumericTraits<base_type>::abs(traits_type::real(x)), |
madcowswe | 15:9c5aaeda36dc | 96 | NumericTraits<base_type>::abs(traits_type::imag(x))); |
madcowswe | 15:9c5aaeda36dc | 97 | } |
madcowswe | 15:9c5aaeda36dc | 98 | |
madcowswe | 15:9c5aaeda36dc | 99 | static inline |
madcowswe | 15:9c5aaeda36dc | 100 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 101 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 102 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 103 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 104 | |
madcowswe | 15:9c5aaeda36dc | 105 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 106 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 107 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 108 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 109 | } |
madcowswe | 15:9c5aaeda36dc | 110 | }; |
madcowswe | 15:9c5aaeda36dc | 111 | |
madcowswe | 15:9c5aaeda36dc | 112 | |
madcowswe | 15:9c5aaeda36dc | 113 | /* |
madcowswe | 15:9c5aaeda36dc | 114 | * numeric traits for standard types |
madcowswe | 15:9c5aaeda36dc | 115 | */ |
madcowswe | 15:9c5aaeda36dc | 116 | |
madcowswe | 15:9c5aaeda36dc | 117 | |
madcowswe | 15:9c5aaeda36dc | 118 | /** |
madcowswe | 15:9c5aaeda36dc | 119 | * \class NumericTraits<char> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 120 | * \brief Traits specialized for char. |
madcowswe | 15:9c5aaeda36dc | 121 | */ |
madcowswe | 15:9c5aaeda36dc | 122 | template<> |
madcowswe | 15:9c5aaeda36dc | 123 | struct NumericTraits<char> { |
madcowswe | 15:9c5aaeda36dc | 124 | typedef char value_type; |
madcowswe | 15:9c5aaeda36dc | 125 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 126 | typedef long sum_type; |
madcowswe | 15:9c5aaeda36dc | 127 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 128 | typedef float float_type; |
madcowswe | 15:9c5aaeda36dc | 129 | typedef char signed_type; |
madcowswe | 15:9c5aaeda36dc | 130 | |
madcowswe | 15:9c5aaeda36dc | 131 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 132 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 133 | |
madcowswe | 15:9c5aaeda36dc | 134 | static inline |
madcowswe | 15:9c5aaeda36dc | 135 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 136 | |
madcowswe | 15:9c5aaeda36dc | 137 | static inline |
madcowswe | 15:9c5aaeda36dc | 138 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 139 | |
madcowswe | 15:9c5aaeda36dc | 140 | static inline |
madcowswe | 15:9c5aaeda36dc | 141 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 142 | |
madcowswe | 15:9c5aaeda36dc | 143 | static inline |
madcowswe | 15:9c5aaeda36dc | 144 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 145 | |
madcowswe | 15:9c5aaeda36dc | 146 | static inline |
madcowswe | 15:9c5aaeda36dc | 147 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 148 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 149 | } |
madcowswe | 15:9c5aaeda36dc | 150 | |
madcowswe | 15:9c5aaeda36dc | 151 | static inline |
madcowswe | 15:9c5aaeda36dc | 152 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 153 | |
madcowswe | 15:9c5aaeda36dc | 154 | static inline |
madcowswe | 15:9c5aaeda36dc | 155 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 156 | |
madcowswe | 15:9c5aaeda36dc | 157 | static inline |
madcowswe | 15:9c5aaeda36dc | 158 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 159 | |
madcowswe | 15:9c5aaeda36dc | 160 | static inline |
madcowswe | 15:9c5aaeda36dc | 161 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 162 | |
madcowswe | 15:9c5aaeda36dc | 163 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 164 | |
madcowswe | 15:9c5aaeda36dc | 165 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 166 | enum { |
madcowswe | 15:9c5aaeda36dc | 167 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 168 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 169 | }; |
madcowswe | 15:9c5aaeda36dc | 170 | }; |
madcowswe | 15:9c5aaeda36dc | 171 | |
madcowswe | 15:9c5aaeda36dc | 172 | |
madcowswe | 15:9c5aaeda36dc | 173 | /** |
madcowswe | 15:9c5aaeda36dc | 174 | * \class NumericTraits<unsigned char> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 175 | * \brief Traits specialized for unsigned char. |
madcowswe | 15:9c5aaeda36dc | 176 | * |
madcowswe | 15:9c5aaeda36dc | 177 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 178 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 179 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 180 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 181 | */ |
madcowswe | 15:9c5aaeda36dc | 182 | template<> |
madcowswe | 15:9c5aaeda36dc | 183 | struct NumericTraits<unsigned char> { |
madcowswe | 15:9c5aaeda36dc | 184 | typedef unsigned char value_type; |
madcowswe | 15:9c5aaeda36dc | 185 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 186 | typedef unsigned long sum_type; |
madcowswe | 15:9c5aaeda36dc | 187 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 188 | typedef float float_type; |
madcowswe | 15:9c5aaeda36dc | 189 | typedef int signed_type; |
madcowswe | 15:9c5aaeda36dc | 190 | |
madcowswe | 15:9c5aaeda36dc | 191 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 192 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 193 | |
madcowswe | 15:9c5aaeda36dc | 194 | static inline |
madcowswe | 15:9c5aaeda36dc | 195 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 196 | |
madcowswe | 15:9c5aaeda36dc | 197 | static inline |
madcowswe | 15:9c5aaeda36dc | 198 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 199 | |
madcowswe | 15:9c5aaeda36dc | 200 | static inline |
madcowswe | 15:9c5aaeda36dc | 201 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 202 | |
madcowswe | 15:9c5aaeda36dc | 203 | static inline |
madcowswe | 15:9c5aaeda36dc | 204 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 205 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 206 | } |
madcowswe | 15:9c5aaeda36dc | 207 | |
madcowswe | 15:9c5aaeda36dc | 208 | static inline |
madcowswe | 15:9c5aaeda36dc | 209 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 210 | |
madcowswe | 15:9c5aaeda36dc | 211 | static inline |
madcowswe | 15:9c5aaeda36dc | 212 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 213 | |
madcowswe | 15:9c5aaeda36dc | 214 | static inline |
madcowswe | 15:9c5aaeda36dc | 215 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 216 | |
madcowswe | 15:9c5aaeda36dc | 217 | static inline |
madcowswe | 15:9c5aaeda36dc | 218 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 219 | |
madcowswe | 15:9c5aaeda36dc | 220 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 221 | |
madcowswe | 15:9c5aaeda36dc | 222 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 223 | enum { |
madcowswe | 15:9c5aaeda36dc | 224 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 225 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 226 | }; |
madcowswe | 15:9c5aaeda36dc | 227 | }; |
madcowswe | 15:9c5aaeda36dc | 228 | |
madcowswe | 15:9c5aaeda36dc | 229 | |
madcowswe | 15:9c5aaeda36dc | 230 | /** |
madcowswe | 15:9c5aaeda36dc | 231 | * \class NumericTraits<short int> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 232 | * \brief Traits specialized for short int. |
madcowswe | 15:9c5aaeda36dc | 233 | */ |
madcowswe | 15:9c5aaeda36dc | 234 | template<> |
madcowswe | 15:9c5aaeda36dc | 235 | struct NumericTraits<short int> { |
madcowswe | 15:9c5aaeda36dc | 236 | typedef short int value_type; |
madcowswe | 15:9c5aaeda36dc | 237 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 238 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 239 | typedef long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 240 | #else |
madcowswe | 15:9c5aaeda36dc | 241 | typedef long sum_type; |
madcowswe | 15:9c5aaeda36dc | 242 | #endif |
madcowswe | 15:9c5aaeda36dc | 243 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 244 | typedef float float_type; |
madcowswe | 15:9c5aaeda36dc | 245 | typedef short int signed_type; |
madcowswe | 15:9c5aaeda36dc | 246 | |
madcowswe | 15:9c5aaeda36dc | 247 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 248 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 249 | |
madcowswe | 15:9c5aaeda36dc | 250 | static inline |
madcowswe | 15:9c5aaeda36dc | 251 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 252 | |
madcowswe | 15:9c5aaeda36dc | 253 | static inline |
madcowswe | 15:9c5aaeda36dc | 254 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 255 | |
madcowswe | 15:9c5aaeda36dc | 256 | static inline |
madcowswe | 15:9c5aaeda36dc | 257 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 258 | |
madcowswe | 15:9c5aaeda36dc | 259 | static inline |
madcowswe | 15:9c5aaeda36dc | 260 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 261 | |
madcowswe | 15:9c5aaeda36dc | 262 | static inline |
madcowswe | 15:9c5aaeda36dc | 263 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 264 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 265 | } |
madcowswe | 15:9c5aaeda36dc | 266 | |
madcowswe | 15:9c5aaeda36dc | 267 | static inline |
madcowswe | 15:9c5aaeda36dc | 268 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 269 | |
madcowswe | 15:9c5aaeda36dc | 270 | static inline |
madcowswe | 15:9c5aaeda36dc | 271 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 272 | |
madcowswe | 15:9c5aaeda36dc | 273 | static inline |
madcowswe | 15:9c5aaeda36dc | 274 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 275 | |
madcowswe | 15:9c5aaeda36dc | 276 | static inline |
madcowswe | 15:9c5aaeda36dc | 277 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 278 | |
madcowswe | 15:9c5aaeda36dc | 279 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 280 | |
madcowswe | 15:9c5aaeda36dc | 281 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 282 | enum { |
madcowswe | 15:9c5aaeda36dc | 283 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 284 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 285 | }; |
madcowswe | 15:9c5aaeda36dc | 286 | }; |
madcowswe | 15:9c5aaeda36dc | 287 | |
madcowswe | 15:9c5aaeda36dc | 288 | |
madcowswe | 15:9c5aaeda36dc | 289 | /** |
madcowswe | 15:9c5aaeda36dc | 290 | * \class NumericTraits<short unsigned int> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 291 | * \brief Traits specialized for short unsigned int. |
madcowswe | 15:9c5aaeda36dc | 292 | * |
madcowswe | 15:9c5aaeda36dc | 293 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 294 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 295 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 296 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 297 | */ |
madcowswe | 15:9c5aaeda36dc | 298 | template<> |
madcowswe | 15:9c5aaeda36dc | 299 | struct NumericTraits<short unsigned int> { |
madcowswe | 15:9c5aaeda36dc | 300 | typedef short unsigned int value_type; |
madcowswe | 15:9c5aaeda36dc | 301 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 302 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 303 | typedef unsigned long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 304 | #else |
madcowswe | 15:9c5aaeda36dc | 305 | typedef unsigned long sum_type; |
madcowswe | 15:9c5aaeda36dc | 306 | #endif |
madcowswe | 15:9c5aaeda36dc | 307 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 308 | typedef float float_type; |
madcowswe | 15:9c5aaeda36dc | 309 | typedef int signed_type; |
madcowswe | 15:9c5aaeda36dc | 310 | |
madcowswe | 15:9c5aaeda36dc | 311 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 312 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 313 | |
madcowswe | 15:9c5aaeda36dc | 314 | static inline |
madcowswe | 15:9c5aaeda36dc | 315 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 316 | |
madcowswe | 15:9c5aaeda36dc | 317 | static inline |
madcowswe | 15:9c5aaeda36dc | 318 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 319 | |
madcowswe | 15:9c5aaeda36dc | 320 | static inline |
madcowswe | 15:9c5aaeda36dc | 321 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 322 | |
madcowswe | 15:9c5aaeda36dc | 323 | static inline |
madcowswe | 15:9c5aaeda36dc | 324 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 325 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 326 | } |
madcowswe | 15:9c5aaeda36dc | 327 | |
madcowswe | 15:9c5aaeda36dc | 328 | static inline |
madcowswe | 15:9c5aaeda36dc | 329 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 330 | |
madcowswe | 15:9c5aaeda36dc | 331 | static inline |
madcowswe | 15:9c5aaeda36dc | 332 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 333 | |
madcowswe | 15:9c5aaeda36dc | 334 | static inline |
madcowswe | 15:9c5aaeda36dc | 335 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 336 | |
madcowswe | 15:9c5aaeda36dc | 337 | static inline |
madcowswe | 15:9c5aaeda36dc | 338 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 339 | |
madcowswe | 15:9c5aaeda36dc | 340 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 341 | |
madcowswe | 15:9c5aaeda36dc | 342 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 343 | enum { |
madcowswe | 15:9c5aaeda36dc | 344 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 345 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 346 | }; |
madcowswe | 15:9c5aaeda36dc | 347 | }; |
madcowswe | 15:9c5aaeda36dc | 348 | |
madcowswe | 15:9c5aaeda36dc | 349 | |
madcowswe | 15:9c5aaeda36dc | 350 | /** |
madcowswe | 15:9c5aaeda36dc | 351 | * \class NumericTraits<int> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 352 | * \brief Traits specialized for int. |
madcowswe | 15:9c5aaeda36dc | 353 | */ |
madcowswe | 15:9c5aaeda36dc | 354 | template<> |
madcowswe | 15:9c5aaeda36dc | 355 | struct NumericTraits<int> { |
madcowswe | 15:9c5aaeda36dc | 356 | typedef int value_type; |
madcowswe | 15:9c5aaeda36dc | 357 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 358 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 359 | typedef long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 360 | #else |
madcowswe | 15:9c5aaeda36dc | 361 | typedef long sum_type; |
madcowswe | 15:9c5aaeda36dc | 362 | #endif |
madcowswe | 15:9c5aaeda36dc | 363 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 364 | typedef double float_type; |
madcowswe | 15:9c5aaeda36dc | 365 | typedef int signed_type; |
madcowswe | 15:9c5aaeda36dc | 366 | |
madcowswe | 15:9c5aaeda36dc | 367 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 368 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 369 | |
madcowswe | 15:9c5aaeda36dc | 370 | static inline |
madcowswe | 15:9c5aaeda36dc | 371 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 372 | |
madcowswe | 15:9c5aaeda36dc | 373 | static inline |
madcowswe | 15:9c5aaeda36dc | 374 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 375 | |
madcowswe | 15:9c5aaeda36dc | 376 | static inline |
madcowswe | 15:9c5aaeda36dc | 377 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 378 | |
madcowswe | 15:9c5aaeda36dc | 379 | static inline |
madcowswe | 15:9c5aaeda36dc | 380 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 381 | |
madcowswe | 15:9c5aaeda36dc | 382 | static inline |
madcowswe | 15:9c5aaeda36dc | 383 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 384 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 385 | } |
madcowswe | 15:9c5aaeda36dc | 386 | |
madcowswe | 15:9c5aaeda36dc | 387 | static inline |
madcowswe | 15:9c5aaeda36dc | 388 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 389 | |
madcowswe | 15:9c5aaeda36dc | 390 | static inline |
madcowswe | 15:9c5aaeda36dc | 391 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 392 | |
madcowswe | 15:9c5aaeda36dc | 393 | static inline |
madcowswe | 15:9c5aaeda36dc | 394 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 395 | |
madcowswe | 15:9c5aaeda36dc | 396 | static inline |
madcowswe | 15:9c5aaeda36dc | 397 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 398 | |
madcowswe | 15:9c5aaeda36dc | 399 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 400 | |
madcowswe | 15:9c5aaeda36dc | 401 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 402 | enum { |
madcowswe | 15:9c5aaeda36dc | 403 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 404 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 405 | }; |
madcowswe | 15:9c5aaeda36dc | 406 | }; |
madcowswe | 15:9c5aaeda36dc | 407 | |
madcowswe | 15:9c5aaeda36dc | 408 | |
madcowswe | 15:9c5aaeda36dc | 409 | /** |
madcowswe | 15:9c5aaeda36dc | 410 | * \class NumericTraits<unsigned int> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 411 | * \brief Traits specialized for unsigned int. |
madcowswe | 15:9c5aaeda36dc | 412 | * |
madcowswe | 15:9c5aaeda36dc | 413 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 414 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 415 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 416 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 417 | */ |
madcowswe | 15:9c5aaeda36dc | 418 | template<> |
madcowswe | 15:9c5aaeda36dc | 419 | struct NumericTraits<unsigned int> { |
madcowswe | 15:9c5aaeda36dc | 420 | typedef unsigned int value_type; |
madcowswe | 15:9c5aaeda36dc | 421 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 422 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 423 | typedef unsigned long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 424 | #else |
madcowswe | 15:9c5aaeda36dc | 425 | typedef unsigned long sum_type; |
madcowswe | 15:9c5aaeda36dc | 426 | #endif |
madcowswe | 15:9c5aaeda36dc | 427 | typedef int diff_type; |
madcowswe | 15:9c5aaeda36dc | 428 | typedef double float_type; |
madcowswe | 15:9c5aaeda36dc | 429 | typedef long signed_type; |
madcowswe | 15:9c5aaeda36dc | 430 | |
madcowswe | 15:9c5aaeda36dc | 431 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 432 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 433 | |
madcowswe | 15:9c5aaeda36dc | 434 | static inline |
madcowswe | 15:9c5aaeda36dc | 435 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 436 | |
madcowswe | 15:9c5aaeda36dc | 437 | static inline |
madcowswe | 15:9c5aaeda36dc | 438 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 439 | |
madcowswe | 15:9c5aaeda36dc | 440 | static inline |
madcowswe | 15:9c5aaeda36dc | 441 | base_type abs(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 442 | |
madcowswe | 15:9c5aaeda36dc | 443 | static inline |
madcowswe | 15:9c5aaeda36dc | 444 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 445 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 446 | } |
madcowswe | 15:9c5aaeda36dc | 447 | |
madcowswe | 15:9c5aaeda36dc | 448 | static inline |
madcowswe | 15:9c5aaeda36dc | 449 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 450 | |
madcowswe | 15:9c5aaeda36dc | 451 | static inline |
madcowswe | 15:9c5aaeda36dc | 452 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 453 | |
madcowswe | 15:9c5aaeda36dc | 454 | static inline |
madcowswe | 15:9c5aaeda36dc | 455 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 456 | |
madcowswe | 15:9c5aaeda36dc | 457 | static inline |
madcowswe | 15:9c5aaeda36dc | 458 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 459 | |
madcowswe | 15:9c5aaeda36dc | 460 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 461 | |
madcowswe | 15:9c5aaeda36dc | 462 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 463 | enum { |
madcowswe | 15:9c5aaeda36dc | 464 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 465 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 466 | }; |
madcowswe | 15:9c5aaeda36dc | 467 | }; |
madcowswe | 15:9c5aaeda36dc | 468 | |
madcowswe | 15:9c5aaeda36dc | 469 | |
madcowswe | 15:9c5aaeda36dc | 470 | /** |
madcowswe | 15:9c5aaeda36dc | 471 | * \class NumericTraits<long> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 472 | * \brief Traits specialized for long. |
madcowswe | 15:9c5aaeda36dc | 473 | */ |
madcowswe | 15:9c5aaeda36dc | 474 | template<> |
madcowswe | 15:9c5aaeda36dc | 475 | struct NumericTraits<long> { |
madcowswe | 15:9c5aaeda36dc | 476 | typedef long value_type; |
madcowswe | 15:9c5aaeda36dc | 477 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 478 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 479 | typedef long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 480 | #else |
madcowswe | 15:9c5aaeda36dc | 481 | typedef long sum_type; |
madcowswe | 15:9c5aaeda36dc | 482 | #endif |
madcowswe | 15:9c5aaeda36dc | 483 | typedef long diff_type; |
madcowswe | 15:9c5aaeda36dc | 484 | typedef double float_type; |
madcowswe | 15:9c5aaeda36dc | 485 | typedef long signed_type; |
madcowswe | 15:9c5aaeda36dc | 486 | |
madcowswe | 15:9c5aaeda36dc | 487 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 488 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 489 | |
madcowswe | 15:9c5aaeda36dc | 490 | static inline |
madcowswe | 15:9c5aaeda36dc | 491 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 492 | |
madcowswe | 15:9c5aaeda36dc | 493 | static inline |
madcowswe | 15:9c5aaeda36dc | 494 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 495 | |
madcowswe | 15:9c5aaeda36dc | 496 | static inline |
madcowswe | 15:9c5aaeda36dc | 497 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 498 | |
madcowswe | 15:9c5aaeda36dc | 499 | static inline |
madcowswe | 15:9c5aaeda36dc | 500 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 501 | |
madcowswe | 15:9c5aaeda36dc | 502 | static inline |
madcowswe | 15:9c5aaeda36dc | 503 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 504 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 505 | } |
madcowswe | 15:9c5aaeda36dc | 506 | |
madcowswe | 15:9c5aaeda36dc | 507 | static inline |
madcowswe | 15:9c5aaeda36dc | 508 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 509 | |
madcowswe | 15:9c5aaeda36dc | 510 | static inline |
madcowswe | 15:9c5aaeda36dc | 511 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 512 | |
madcowswe | 15:9c5aaeda36dc | 513 | static inline |
madcowswe | 15:9c5aaeda36dc | 514 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 515 | |
madcowswe | 15:9c5aaeda36dc | 516 | static inline |
madcowswe | 15:9c5aaeda36dc | 517 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 518 | |
madcowswe | 15:9c5aaeda36dc | 519 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 520 | |
madcowswe | 15:9c5aaeda36dc | 521 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 522 | enum { |
madcowswe | 15:9c5aaeda36dc | 523 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 524 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 525 | }; |
madcowswe | 15:9c5aaeda36dc | 526 | }; |
madcowswe | 15:9c5aaeda36dc | 527 | |
madcowswe | 15:9c5aaeda36dc | 528 | |
madcowswe | 15:9c5aaeda36dc | 529 | /** |
madcowswe | 15:9c5aaeda36dc | 530 | * \class NumericTraits<unsigned long> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 531 | * \brief Traits specialized for unsigned long. |
madcowswe | 15:9c5aaeda36dc | 532 | * |
madcowswe | 15:9c5aaeda36dc | 533 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 534 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 535 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 536 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 537 | */ |
madcowswe | 15:9c5aaeda36dc | 538 | template<> |
madcowswe | 15:9c5aaeda36dc | 539 | struct NumericTraits<unsigned long> { |
madcowswe | 15:9c5aaeda36dc | 540 | typedef unsigned long value_type; |
madcowswe | 15:9c5aaeda36dc | 541 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 542 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 543 | typedef unsigned long long sum_type; |
madcowswe | 15:9c5aaeda36dc | 544 | #else |
madcowswe | 15:9c5aaeda36dc | 545 | typedef unsigned long sum_type; |
madcowswe | 15:9c5aaeda36dc | 546 | #endif |
madcowswe | 15:9c5aaeda36dc | 547 | typedef unsigned long diff_type; |
madcowswe | 15:9c5aaeda36dc | 548 | typedef double float_type; |
madcowswe | 15:9c5aaeda36dc | 549 | typedef long signed_type; |
madcowswe | 15:9c5aaeda36dc | 550 | |
madcowswe | 15:9c5aaeda36dc | 551 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 552 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 553 | |
madcowswe | 15:9c5aaeda36dc | 554 | static inline |
madcowswe | 15:9c5aaeda36dc | 555 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 556 | |
madcowswe | 15:9c5aaeda36dc | 557 | static inline |
madcowswe | 15:9c5aaeda36dc | 558 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 559 | |
madcowswe | 15:9c5aaeda36dc | 560 | static inline |
madcowswe | 15:9c5aaeda36dc | 561 | base_type abs(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 562 | |
madcowswe | 15:9c5aaeda36dc | 563 | static inline |
madcowswe | 15:9c5aaeda36dc | 564 | value_type sqrt(argument_type x) { |
madcowswe | 15:9c5aaeda36dc | 565 | return static_cast<value_type>(std::sqrt(static_cast<float_type>(x))); |
madcowswe | 15:9c5aaeda36dc | 566 | } |
madcowswe | 15:9c5aaeda36dc | 567 | |
madcowswe | 15:9c5aaeda36dc | 568 | static inline |
madcowswe | 15:9c5aaeda36dc | 569 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 570 | |
madcowswe | 15:9c5aaeda36dc | 571 | static inline |
madcowswe | 15:9c5aaeda36dc | 572 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 573 | |
madcowswe | 15:9c5aaeda36dc | 574 | static inline |
madcowswe | 15:9c5aaeda36dc | 575 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 576 | |
madcowswe | 15:9c5aaeda36dc | 577 | static inline |
madcowswe | 15:9c5aaeda36dc | 578 | bool equals(argument_type lhs, argument_type rhs) { return lhs == rhs; } |
madcowswe | 15:9c5aaeda36dc | 579 | |
madcowswe | 15:9c5aaeda36dc | 580 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 581 | |
madcowswe | 15:9c5aaeda36dc | 582 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 583 | enum { |
madcowswe | 15:9c5aaeda36dc | 584 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 585 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 586 | }; |
madcowswe | 15:9c5aaeda36dc | 587 | }; |
madcowswe | 15:9c5aaeda36dc | 588 | |
madcowswe | 15:9c5aaeda36dc | 589 | |
madcowswe | 15:9c5aaeda36dc | 590 | /** |
madcowswe | 15:9c5aaeda36dc | 591 | * \class NumericTraits<float> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 592 | * \brief Traits specialized for float. |
madcowswe | 15:9c5aaeda36dc | 593 | */ |
madcowswe | 15:9c5aaeda36dc | 594 | template<> |
madcowswe | 15:9c5aaeda36dc | 595 | struct NumericTraits<float> { |
madcowswe | 15:9c5aaeda36dc | 596 | typedef float value_type; |
madcowswe | 15:9c5aaeda36dc | 597 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 598 | typedef double sum_type; |
madcowswe | 15:9c5aaeda36dc | 599 | typedef float diff_type; |
madcowswe | 15:9c5aaeda36dc | 600 | typedef float float_type; |
madcowswe | 15:9c5aaeda36dc | 601 | typedef float signed_type; |
madcowswe | 15:9c5aaeda36dc | 602 | |
madcowswe | 15:9c5aaeda36dc | 603 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 604 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 605 | |
madcowswe | 15:9c5aaeda36dc | 606 | static inline |
madcowswe | 15:9c5aaeda36dc | 607 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 608 | |
madcowswe | 15:9c5aaeda36dc | 609 | static inline |
madcowswe | 15:9c5aaeda36dc | 610 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 611 | |
madcowswe | 15:9c5aaeda36dc | 612 | static inline |
madcowswe | 15:9c5aaeda36dc | 613 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 614 | |
madcowswe | 15:9c5aaeda36dc | 615 | static inline |
madcowswe | 15:9c5aaeda36dc | 616 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 617 | |
madcowswe | 15:9c5aaeda36dc | 618 | static inline |
madcowswe | 15:9c5aaeda36dc | 619 | value_type sqrt(argument_type x) { return std::sqrt(x); } |
madcowswe | 15:9c5aaeda36dc | 620 | |
madcowswe | 15:9c5aaeda36dc | 621 | static inline |
madcowswe | 15:9c5aaeda36dc | 622 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 623 | |
madcowswe | 15:9c5aaeda36dc | 624 | static inline |
madcowswe | 15:9c5aaeda36dc | 625 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 626 | |
madcowswe | 15:9c5aaeda36dc | 627 | static inline |
madcowswe | 15:9c5aaeda36dc | 628 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 629 | |
madcowswe | 15:9c5aaeda36dc | 630 | static inline |
madcowswe | 15:9c5aaeda36dc | 631 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 632 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 633 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 634 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 635 | |
madcowswe | 15:9c5aaeda36dc | 636 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 637 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 638 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 639 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 640 | } |
madcowswe | 15:9c5aaeda36dc | 641 | |
madcowswe | 15:9c5aaeda36dc | 642 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 643 | |
madcowswe | 15:9c5aaeda36dc | 644 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 645 | enum { |
madcowswe | 15:9c5aaeda36dc | 646 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 647 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 648 | }; |
madcowswe | 15:9c5aaeda36dc | 649 | }; |
madcowswe | 15:9c5aaeda36dc | 650 | |
madcowswe | 15:9c5aaeda36dc | 651 | |
madcowswe | 15:9c5aaeda36dc | 652 | /** |
madcowswe | 15:9c5aaeda36dc | 653 | * \class NumericTraits<double> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 654 | * \brief Traits specialized for double. |
madcowswe | 15:9c5aaeda36dc | 655 | */ |
madcowswe | 15:9c5aaeda36dc | 656 | template<> |
madcowswe | 15:9c5aaeda36dc | 657 | struct NumericTraits<double> { |
madcowswe | 15:9c5aaeda36dc | 658 | typedef double value_type; |
madcowswe | 15:9c5aaeda36dc | 659 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 660 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 661 | typedef long double sum_type; |
madcowswe | 15:9c5aaeda36dc | 662 | #else |
madcowswe | 15:9c5aaeda36dc | 663 | typedef double sum_type; |
madcowswe | 15:9c5aaeda36dc | 664 | #endif |
madcowswe | 15:9c5aaeda36dc | 665 | typedef double diff_type; |
madcowswe | 15:9c5aaeda36dc | 666 | typedef double float_type; |
madcowswe | 15:9c5aaeda36dc | 667 | typedef double signed_type; |
madcowswe | 15:9c5aaeda36dc | 668 | |
madcowswe | 15:9c5aaeda36dc | 669 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 670 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 671 | |
madcowswe | 15:9c5aaeda36dc | 672 | static inline |
madcowswe | 15:9c5aaeda36dc | 673 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 674 | |
madcowswe | 15:9c5aaeda36dc | 675 | static inline |
madcowswe | 15:9c5aaeda36dc | 676 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 677 | |
madcowswe | 15:9c5aaeda36dc | 678 | static inline |
madcowswe | 15:9c5aaeda36dc | 679 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 680 | |
madcowswe | 15:9c5aaeda36dc | 681 | static inline |
madcowswe | 15:9c5aaeda36dc | 682 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 683 | |
madcowswe | 15:9c5aaeda36dc | 684 | static inline |
madcowswe | 15:9c5aaeda36dc | 685 | value_type sqrt(argument_type x) { return std::sqrt(x); } |
madcowswe | 15:9c5aaeda36dc | 686 | |
madcowswe | 15:9c5aaeda36dc | 687 | static inline |
madcowswe | 15:9c5aaeda36dc | 688 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 689 | |
madcowswe | 15:9c5aaeda36dc | 690 | static inline |
madcowswe | 15:9c5aaeda36dc | 691 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 692 | |
madcowswe | 15:9c5aaeda36dc | 693 | static inline |
madcowswe | 15:9c5aaeda36dc | 694 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 695 | |
madcowswe | 15:9c5aaeda36dc | 696 | static inline |
madcowswe | 15:9c5aaeda36dc | 697 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 698 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 699 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 700 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 701 | |
madcowswe | 15:9c5aaeda36dc | 702 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 703 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 704 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 705 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 706 | } |
madcowswe | 15:9c5aaeda36dc | 707 | |
madcowswe | 15:9c5aaeda36dc | 708 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 709 | |
madcowswe | 15:9c5aaeda36dc | 710 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 711 | enum { |
madcowswe | 15:9c5aaeda36dc | 712 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 713 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 714 | }; |
madcowswe | 15:9c5aaeda36dc | 715 | }; |
madcowswe | 15:9c5aaeda36dc | 716 | |
madcowswe | 15:9c5aaeda36dc | 717 | |
madcowswe | 15:9c5aaeda36dc | 718 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 719 | /** |
madcowswe | 15:9c5aaeda36dc | 720 | * \class NumericTraits<long double> NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 721 | * \brief Traits specialized for long double. |
madcowswe | 15:9c5aaeda36dc | 722 | */ |
madcowswe | 15:9c5aaeda36dc | 723 | template<> |
madcowswe | 15:9c5aaeda36dc | 724 | struct NumericTraits<long double> { |
madcowswe | 15:9c5aaeda36dc | 725 | typedef long double value_type; |
madcowswe | 15:9c5aaeda36dc | 726 | typedef value_type base_type; |
madcowswe | 15:9c5aaeda36dc | 727 | typedef long double sum_type; |
madcowswe | 15:9c5aaeda36dc | 728 | typedef long double diff_type; |
madcowswe | 15:9c5aaeda36dc | 729 | typedef long double float_type; |
madcowswe | 15:9c5aaeda36dc | 730 | typedef long double signed_type; |
madcowswe | 15:9c5aaeda36dc | 731 | |
madcowswe | 15:9c5aaeda36dc | 732 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 733 | typedef value_type argument_type; |
madcowswe | 15:9c5aaeda36dc | 734 | |
madcowswe | 15:9c5aaeda36dc | 735 | static inline |
madcowswe | 15:9c5aaeda36dc | 736 | base_type real(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 737 | |
madcowswe | 15:9c5aaeda36dc | 738 | static inline |
madcowswe | 15:9c5aaeda36dc | 739 | base_type imag(argument_type) { return 0; } |
madcowswe | 15:9c5aaeda36dc | 740 | |
madcowswe | 15:9c5aaeda36dc | 741 | static inline |
madcowswe | 15:9c5aaeda36dc | 742 | value_type conj(argument_type x) { return x; } |
madcowswe | 15:9c5aaeda36dc | 743 | |
madcowswe | 15:9c5aaeda36dc | 744 | static inline |
madcowswe | 15:9c5aaeda36dc | 745 | base_type abs(argument_type x) { return std::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 746 | |
madcowswe | 15:9c5aaeda36dc | 747 | static inline |
madcowswe | 15:9c5aaeda36dc | 748 | value_type sqrt(argument_type x) { return std::sqrt(x); } |
madcowswe | 15:9c5aaeda36dc | 749 | |
madcowswe | 15:9c5aaeda36dc | 750 | static inline |
madcowswe | 15:9c5aaeda36dc | 751 | base_type norm_1(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 752 | |
madcowswe | 15:9c5aaeda36dc | 753 | static inline |
madcowswe | 15:9c5aaeda36dc | 754 | base_type norm_2(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 755 | |
madcowswe | 15:9c5aaeda36dc | 756 | static inline |
madcowswe | 15:9c5aaeda36dc | 757 | base_type norm_inf(argument_type x) { return traits_type::abs(x); } |
madcowswe | 15:9c5aaeda36dc | 758 | |
madcowswe | 15:9c5aaeda36dc | 759 | static inline |
madcowswe | 15:9c5aaeda36dc | 760 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 761 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 762 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 763 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 764 | |
madcowswe | 15:9c5aaeda36dc | 765 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 766 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 767 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 768 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 769 | } |
madcowswe | 15:9c5aaeda36dc | 770 | |
madcowswe | 15:9c5aaeda36dc | 771 | enum { is_complex = false }; |
madcowswe | 15:9c5aaeda36dc | 772 | |
madcowswe | 15:9c5aaeda36dc | 773 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 774 | enum { |
madcowswe | 15:9c5aaeda36dc | 775 | ops_plus = 1, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 776 | ops_muls = 1 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 777 | }; |
madcowswe | 15:9c5aaeda36dc | 778 | }; |
madcowswe | 15:9c5aaeda36dc | 779 | #endif // TVMET_HAVE_LONG_DOUBLE |
madcowswe | 15:9c5aaeda36dc | 780 | |
madcowswe | 15:9c5aaeda36dc | 781 | |
madcowswe | 15:9c5aaeda36dc | 782 | /* |
madcowswe | 15:9c5aaeda36dc | 783 | * numeric traits for complex types |
madcowswe | 15:9c5aaeda36dc | 784 | */ |
madcowswe | 15:9c5aaeda36dc | 785 | #if defined(TVMET_HAVE_COMPLEX) |
madcowswe | 15:9c5aaeda36dc | 786 | |
madcowswe | 15:9c5aaeda36dc | 787 | /** |
madcowswe | 15:9c5aaeda36dc | 788 | * \class NumericTraits< std::complex<int> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 789 | * \brief Traits specialized for std::complex<int>. |
madcowswe | 15:9c5aaeda36dc | 790 | */ |
madcowswe | 15:9c5aaeda36dc | 791 | template<> |
madcowswe | 15:9c5aaeda36dc | 792 | struct NumericTraits< std::complex<int> > { |
madcowswe | 15:9c5aaeda36dc | 793 | typedef int base_type; |
madcowswe | 15:9c5aaeda36dc | 794 | typedef std::complex<int> value_type; |
madcowswe | 15:9c5aaeda36dc | 795 | typedef std::complex<long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 796 | typedef std::complex<int> diff_type; |
madcowswe | 15:9c5aaeda36dc | 797 | typedef std::complex<float> float_type; |
madcowswe | 15:9c5aaeda36dc | 798 | typedef std::complex<int> signed_type; |
madcowswe | 15:9c5aaeda36dc | 799 | |
madcowswe | 15:9c5aaeda36dc | 800 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 801 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 802 | |
madcowswe | 15:9c5aaeda36dc | 803 | static inline |
madcowswe | 15:9c5aaeda36dc | 804 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 805 | |
madcowswe | 15:9c5aaeda36dc | 806 | static inline |
madcowswe | 15:9c5aaeda36dc | 807 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 808 | |
madcowswe | 15:9c5aaeda36dc | 809 | static inline |
madcowswe | 15:9c5aaeda36dc | 810 | value_type conj(argument_type z) { return std::conj(z); } |
madcowswe | 15:9c5aaeda36dc | 811 | |
madcowswe | 15:9c5aaeda36dc | 812 | static inline |
madcowswe | 15:9c5aaeda36dc | 813 | base_type abs(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 814 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 815 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 816 | |
madcowswe | 15:9c5aaeda36dc | 817 | // XXX probably case of overrun; header complex uses scaling |
madcowswe | 15:9c5aaeda36dc | 818 | return static_cast<base_type>(NumericTraits<base_type>::sqrt(x * x + y * y)); |
madcowswe | 15:9c5aaeda36dc | 819 | } |
madcowswe | 15:9c5aaeda36dc | 820 | |
madcowswe | 15:9c5aaeda36dc | 821 | static /* inline */ |
madcowswe | 15:9c5aaeda36dc | 822 | value_type sqrt(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 823 | // borrowed and adapted from header complex |
madcowswe | 15:9c5aaeda36dc | 824 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 825 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 826 | |
madcowswe | 15:9c5aaeda36dc | 827 | if(x == base_type()) { |
madcowswe | 15:9c5aaeda36dc | 828 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 829 | NumericTraits<base_type>::abs(y) / 2); |
madcowswe | 15:9c5aaeda36dc | 830 | return value_type(t, y < base_type() ? -t : t); |
madcowswe | 15:9c5aaeda36dc | 831 | } |
madcowswe | 15:9c5aaeda36dc | 832 | else { |
madcowswe | 15:9c5aaeda36dc | 833 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 834 | 2 * (traits_type::abs(z) |
madcowswe | 15:9c5aaeda36dc | 835 | + NumericTraits<base_type>::abs(x))); |
madcowswe | 15:9c5aaeda36dc | 836 | base_type u = t / 2; |
madcowswe | 15:9c5aaeda36dc | 837 | return x > base_type() |
madcowswe | 15:9c5aaeda36dc | 838 | ? value_type(u, y / t) |
madcowswe | 15:9c5aaeda36dc | 839 | : value_type(NumericTraits<base_type>::abs(y) / t, y < base_type() ? -u : u); |
madcowswe | 15:9c5aaeda36dc | 840 | } |
madcowswe | 15:9c5aaeda36dc | 841 | } |
madcowswe | 15:9c5aaeda36dc | 842 | |
madcowswe | 15:9c5aaeda36dc | 843 | static inline |
madcowswe | 15:9c5aaeda36dc | 844 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 845 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 846 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 847 | } |
madcowswe | 15:9c5aaeda36dc | 848 | |
madcowswe | 15:9c5aaeda36dc | 849 | static inline |
madcowswe | 15:9c5aaeda36dc | 850 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 851 | |
madcowswe | 15:9c5aaeda36dc | 852 | static inline |
madcowswe | 15:9c5aaeda36dc | 853 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 854 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 855 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 856 | } |
madcowswe | 15:9c5aaeda36dc | 857 | |
madcowswe | 15:9c5aaeda36dc | 858 | static inline |
madcowswe | 15:9c5aaeda36dc | 859 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 860 | return (traits_type::real(lhs) == traits_type::real(rhs)) |
madcowswe | 15:9c5aaeda36dc | 861 | && (traits_type::imag(lhs) == traits_type::imag(rhs)); |
madcowswe | 15:9c5aaeda36dc | 862 | } |
madcowswe | 15:9c5aaeda36dc | 863 | |
madcowswe | 15:9c5aaeda36dc | 864 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 865 | |
madcowswe | 15:9c5aaeda36dc | 866 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 867 | enum { |
madcowswe | 15:9c5aaeda36dc | 868 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 869 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 870 | }; |
madcowswe | 15:9c5aaeda36dc | 871 | }; |
madcowswe | 15:9c5aaeda36dc | 872 | |
madcowswe | 15:9c5aaeda36dc | 873 | |
madcowswe | 15:9c5aaeda36dc | 874 | /** |
madcowswe | 15:9c5aaeda36dc | 875 | * \class NumericTraits< std::complex<unsigned int> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 876 | * \brief Traits specialized for std::complex<unsigned int>. |
madcowswe | 15:9c5aaeda36dc | 877 | * |
madcowswe | 15:9c5aaeda36dc | 878 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 879 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 880 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 881 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 882 | */ |
madcowswe | 15:9c5aaeda36dc | 883 | template<> |
madcowswe | 15:9c5aaeda36dc | 884 | struct NumericTraits< std::complex<unsigned int> > { |
madcowswe | 15:9c5aaeda36dc | 885 | typedef unsigned int base_type; |
madcowswe | 15:9c5aaeda36dc | 886 | typedef std::complex<unsigned int> value_type; |
madcowswe | 15:9c5aaeda36dc | 887 | typedef std::complex<unsigned long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 888 | typedef std::complex<int> diff_type; |
madcowswe | 15:9c5aaeda36dc | 889 | typedef std::complex<float> float_type; |
madcowswe | 15:9c5aaeda36dc | 890 | typedef std::complex<int> signed_type; |
madcowswe | 15:9c5aaeda36dc | 891 | |
madcowswe | 15:9c5aaeda36dc | 892 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 893 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 894 | |
madcowswe | 15:9c5aaeda36dc | 895 | static inline |
madcowswe | 15:9c5aaeda36dc | 896 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 897 | |
madcowswe | 15:9c5aaeda36dc | 898 | static inline |
madcowswe | 15:9c5aaeda36dc | 899 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 900 | |
madcowswe | 15:9c5aaeda36dc | 901 | static inline |
madcowswe | 15:9c5aaeda36dc | 902 | base_type abs(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 903 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 904 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 905 | |
madcowswe | 15:9c5aaeda36dc | 906 | // XXX probably case of overrun; header complex uses scaling |
madcowswe | 15:9c5aaeda36dc | 907 | return static_cast<base_type>(NumericTraits<base_type>::sqrt(x * x + y * y)); |
madcowswe | 15:9c5aaeda36dc | 908 | } |
madcowswe | 15:9c5aaeda36dc | 909 | |
madcowswe | 15:9c5aaeda36dc | 910 | static /* inline */ |
madcowswe | 15:9c5aaeda36dc | 911 | value_type sqrt(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 912 | // borrowed and adapted from header complex |
madcowswe | 15:9c5aaeda36dc | 913 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 914 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 915 | |
madcowswe | 15:9c5aaeda36dc | 916 | if(x == base_type()) { |
madcowswe | 15:9c5aaeda36dc | 917 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 918 | NumericTraits<base_type>::abs(y) / 2); |
madcowswe | 15:9c5aaeda36dc | 919 | return value_type(t, t); |
madcowswe | 15:9c5aaeda36dc | 920 | } |
madcowswe | 15:9c5aaeda36dc | 921 | else { |
madcowswe | 15:9c5aaeda36dc | 922 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 923 | 2 * (traits_type::abs(z) |
madcowswe | 15:9c5aaeda36dc | 924 | + NumericTraits<base_type>::abs(x))); |
madcowswe | 15:9c5aaeda36dc | 925 | return value_type(t / 2, y / t); |
madcowswe | 15:9c5aaeda36dc | 926 | } |
madcowswe | 15:9c5aaeda36dc | 927 | } |
madcowswe | 15:9c5aaeda36dc | 928 | |
madcowswe | 15:9c5aaeda36dc | 929 | static inline |
madcowswe | 15:9c5aaeda36dc | 930 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 931 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 932 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 933 | } |
madcowswe | 15:9c5aaeda36dc | 934 | |
madcowswe | 15:9c5aaeda36dc | 935 | static inline |
madcowswe | 15:9c5aaeda36dc | 936 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 937 | |
madcowswe | 15:9c5aaeda36dc | 938 | static inline |
madcowswe | 15:9c5aaeda36dc | 939 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 940 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 941 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 942 | } |
madcowswe | 15:9c5aaeda36dc | 943 | |
madcowswe | 15:9c5aaeda36dc | 944 | static inline |
madcowswe | 15:9c5aaeda36dc | 945 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 946 | return (traits_type::real(lhs) == traits_type::real(rhs)) |
madcowswe | 15:9c5aaeda36dc | 947 | && (traits_type::imag(lhs) == traits_type::imag(rhs)); |
madcowswe | 15:9c5aaeda36dc | 948 | } |
madcowswe | 15:9c5aaeda36dc | 949 | |
madcowswe | 15:9c5aaeda36dc | 950 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 951 | |
madcowswe | 15:9c5aaeda36dc | 952 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 953 | enum { |
madcowswe | 15:9c5aaeda36dc | 954 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 955 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 956 | }; |
madcowswe | 15:9c5aaeda36dc | 957 | }; |
madcowswe | 15:9c5aaeda36dc | 958 | |
madcowswe | 15:9c5aaeda36dc | 959 | |
madcowswe | 15:9c5aaeda36dc | 960 | /** |
madcowswe | 15:9c5aaeda36dc | 961 | * \class NumericTraits< std::complex<long> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 962 | * \brief Traits specialized for std::complex<long>. |
madcowswe | 15:9c5aaeda36dc | 963 | */ |
madcowswe | 15:9c5aaeda36dc | 964 | template<> |
madcowswe | 15:9c5aaeda36dc | 965 | struct NumericTraits< std::complex<long> > { |
madcowswe | 15:9c5aaeda36dc | 966 | typedef long base_type; |
madcowswe | 15:9c5aaeda36dc | 967 | typedef std::complex<long> value_type; |
madcowswe | 15:9c5aaeda36dc | 968 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 969 | typedef std::complex<long long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 970 | #else |
madcowswe | 15:9c5aaeda36dc | 971 | typedef std::complex<long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 972 | #endif |
madcowswe | 15:9c5aaeda36dc | 973 | typedef std::complex<int> diff_type; |
madcowswe | 15:9c5aaeda36dc | 974 | typedef std::complex<float> float_type; |
madcowswe | 15:9c5aaeda36dc | 975 | typedef std::complex<int> signed_type; |
madcowswe | 15:9c5aaeda36dc | 976 | |
madcowswe | 15:9c5aaeda36dc | 977 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 978 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 979 | |
madcowswe | 15:9c5aaeda36dc | 980 | static inline |
madcowswe | 15:9c5aaeda36dc | 981 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 982 | |
madcowswe | 15:9c5aaeda36dc | 983 | static inline |
madcowswe | 15:9c5aaeda36dc | 984 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 985 | |
madcowswe | 15:9c5aaeda36dc | 986 | static inline |
madcowswe | 15:9c5aaeda36dc | 987 | value_type conj(argument_type z) { return std::conj(z); } |
madcowswe | 15:9c5aaeda36dc | 988 | |
madcowswe | 15:9c5aaeda36dc | 989 | static inline |
madcowswe | 15:9c5aaeda36dc | 990 | base_type abs(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 991 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 992 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 993 | |
madcowswe | 15:9c5aaeda36dc | 994 | // XXX probably case of overrun; header complex uses scaling |
madcowswe | 15:9c5aaeda36dc | 995 | return static_cast<base_type>(NumericTraits<base_type>::sqrt(x * x + y * y)); |
madcowswe | 15:9c5aaeda36dc | 996 | } |
madcowswe | 15:9c5aaeda36dc | 997 | |
madcowswe | 15:9c5aaeda36dc | 998 | static /* inline */ |
madcowswe | 15:9c5aaeda36dc | 999 | value_type sqrt(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1000 | // borrowed and adapted from header complex |
madcowswe | 15:9c5aaeda36dc | 1001 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 1002 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 1003 | |
madcowswe | 15:9c5aaeda36dc | 1004 | if(x == base_type()) { |
madcowswe | 15:9c5aaeda36dc | 1005 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1006 | NumericTraits<base_type>::abs(y) / 2); |
madcowswe | 15:9c5aaeda36dc | 1007 | return value_type(t, y < base_type() ? -t : t); |
madcowswe | 15:9c5aaeda36dc | 1008 | } |
madcowswe | 15:9c5aaeda36dc | 1009 | else { |
madcowswe | 15:9c5aaeda36dc | 1010 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1011 | 2 * (traits_type::abs(z) |
madcowswe | 15:9c5aaeda36dc | 1012 | + NumericTraits<base_type>::abs(x))); |
madcowswe | 15:9c5aaeda36dc | 1013 | base_type u = t / 2; |
madcowswe | 15:9c5aaeda36dc | 1014 | return x > base_type() |
madcowswe | 15:9c5aaeda36dc | 1015 | ? value_type(u, y / t) |
madcowswe | 15:9c5aaeda36dc | 1016 | : value_type(NumericTraits<base_type>::abs(y) / t, y < base_type() ? -u : u); |
madcowswe | 15:9c5aaeda36dc | 1017 | } |
madcowswe | 15:9c5aaeda36dc | 1018 | } |
madcowswe | 15:9c5aaeda36dc | 1019 | |
madcowswe | 15:9c5aaeda36dc | 1020 | static inline |
madcowswe | 15:9c5aaeda36dc | 1021 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1022 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 1023 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1024 | } |
madcowswe | 15:9c5aaeda36dc | 1025 | |
madcowswe | 15:9c5aaeda36dc | 1026 | static inline |
madcowswe | 15:9c5aaeda36dc | 1027 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1028 | |
madcowswe | 15:9c5aaeda36dc | 1029 | static inline |
madcowswe | 15:9c5aaeda36dc | 1030 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1031 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 1032 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1033 | } |
madcowswe | 15:9c5aaeda36dc | 1034 | |
madcowswe | 15:9c5aaeda36dc | 1035 | static inline |
madcowswe | 15:9c5aaeda36dc | 1036 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 1037 | return (traits_type::real(lhs) == traits_type::real(rhs)) |
madcowswe | 15:9c5aaeda36dc | 1038 | && (traits_type::imag(lhs) == traits_type::imag(rhs)); |
madcowswe | 15:9c5aaeda36dc | 1039 | } |
madcowswe | 15:9c5aaeda36dc | 1040 | |
madcowswe | 15:9c5aaeda36dc | 1041 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 1042 | |
madcowswe | 15:9c5aaeda36dc | 1043 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 1044 | enum { |
madcowswe | 15:9c5aaeda36dc | 1045 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 1046 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 1047 | }; |
madcowswe | 15:9c5aaeda36dc | 1048 | }; |
madcowswe | 15:9c5aaeda36dc | 1049 | |
madcowswe | 15:9c5aaeda36dc | 1050 | |
madcowswe | 15:9c5aaeda36dc | 1051 | /** |
madcowswe | 15:9c5aaeda36dc | 1052 | * \class NumericTraits< std::complex<unsigned long> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 1053 | * \brief Traits specialized for std::complex<unsigned long>. |
madcowswe | 15:9c5aaeda36dc | 1054 | * |
madcowswe | 15:9c5aaeda36dc | 1055 | * \note Normally it doesn't make sense to call <tt>conj</tt> |
madcowswe | 15:9c5aaeda36dc | 1056 | * for an unsigned type! An unary minus operator |
madcowswe | 15:9c5aaeda36dc | 1057 | * applied to unsigned type will result unsigned. Therefore |
madcowswe | 15:9c5aaeda36dc | 1058 | * this function is missing here. |
madcowswe | 15:9c5aaeda36dc | 1059 | */ |
madcowswe | 15:9c5aaeda36dc | 1060 | template<> |
madcowswe | 15:9c5aaeda36dc | 1061 | struct NumericTraits< std::complex<unsigned long> > { |
madcowswe | 15:9c5aaeda36dc | 1062 | typedef unsigned long base_type; |
madcowswe | 15:9c5aaeda36dc | 1063 | typedef std::complex<unsigned long> value_type; |
madcowswe | 15:9c5aaeda36dc | 1064 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 15:9c5aaeda36dc | 1065 | typedef std::complex<unsigned long long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1066 | #else |
madcowswe | 15:9c5aaeda36dc | 1067 | typedef std::complex<unsigned long> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1068 | #endif |
madcowswe | 15:9c5aaeda36dc | 1069 | typedef std::complex<long> diff_type; |
madcowswe | 15:9c5aaeda36dc | 1070 | typedef std::complex<float> float_type; |
madcowswe | 15:9c5aaeda36dc | 1071 | typedef std::complex<long> signed_type; |
madcowswe | 15:9c5aaeda36dc | 1072 | |
madcowswe | 15:9c5aaeda36dc | 1073 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 1074 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 1075 | |
madcowswe | 15:9c5aaeda36dc | 1076 | static inline |
madcowswe | 15:9c5aaeda36dc | 1077 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 1078 | |
madcowswe | 15:9c5aaeda36dc | 1079 | static inline |
madcowswe | 15:9c5aaeda36dc | 1080 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 1081 | |
madcowswe | 15:9c5aaeda36dc | 1082 | static inline |
madcowswe | 15:9c5aaeda36dc | 1083 | base_type abs(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1084 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 1085 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 1086 | |
madcowswe | 15:9c5aaeda36dc | 1087 | // XXX probably case of overrun; header complex uses scaling |
madcowswe | 15:9c5aaeda36dc | 1088 | return static_cast<base_type>(NumericTraits<base_type>::sqrt(x * x + y * y)); |
madcowswe | 15:9c5aaeda36dc | 1089 | } |
madcowswe | 15:9c5aaeda36dc | 1090 | |
madcowswe | 15:9c5aaeda36dc | 1091 | static /* inline */ |
madcowswe | 15:9c5aaeda36dc | 1092 | value_type sqrt(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1093 | // borrowed and adapted from header complex |
madcowswe | 15:9c5aaeda36dc | 1094 | base_type x = z.real(); |
madcowswe | 15:9c5aaeda36dc | 1095 | base_type y = z.imag(); |
madcowswe | 15:9c5aaeda36dc | 1096 | |
madcowswe | 15:9c5aaeda36dc | 1097 | if(x == base_type()) { |
madcowswe | 15:9c5aaeda36dc | 1098 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1099 | NumericTraits<base_type>::abs(y) / 2); |
madcowswe | 15:9c5aaeda36dc | 1100 | return value_type(t, t); |
madcowswe | 15:9c5aaeda36dc | 1101 | } |
madcowswe | 15:9c5aaeda36dc | 1102 | else { |
madcowswe | 15:9c5aaeda36dc | 1103 | base_type t = NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1104 | 2 * (traits_type::abs(z) |
madcowswe | 15:9c5aaeda36dc | 1105 | + NumericTraits<base_type>::abs(x))); |
madcowswe | 15:9c5aaeda36dc | 1106 | return value_type(t / 2, y / t); |
madcowswe | 15:9c5aaeda36dc | 1107 | } |
madcowswe | 15:9c5aaeda36dc | 1108 | } |
madcowswe | 15:9c5aaeda36dc | 1109 | |
madcowswe | 15:9c5aaeda36dc | 1110 | static inline |
madcowswe | 15:9c5aaeda36dc | 1111 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1112 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 1113 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1114 | } |
madcowswe | 15:9c5aaeda36dc | 1115 | |
madcowswe | 15:9c5aaeda36dc | 1116 | static inline |
madcowswe | 15:9c5aaeda36dc | 1117 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1118 | |
madcowswe | 15:9c5aaeda36dc | 1119 | static inline |
madcowswe | 15:9c5aaeda36dc | 1120 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1121 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 1122 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1123 | } |
madcowswe | 15:9c5aaeda36dc | 1124 | |
madcowswe | 15:9c5aaeda36dc | 1125 | static inline |
madcowswe | 15:9c5aaeda36dc | 1126 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 1127 | return (traits_type::real(lhs) == traits_type::real(rhs)) |
madcowswe | 15:9c5aaeda36dc | 1128 | && (traits_type::imag(lhs) == traits_type::imag(rhs)); |
madcowswe | 15:9c5aaeda36dc | 1129 | } |
madcowswe | 15:9c5aaeda36dc | 1130 | |
madcowswe | 15:9c5aaeda36dc | 1131 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 1132 | |
madcowswe | 15:9c5aaeda36dc | 1133 | /** Complexity on operations.*/ |
madcowswe | 15:9c5aaeda36dc | 1134 | enum { |
madcowswe | 15:9c5aaeda36dc | 1135 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 1136 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 1137 | }; |
madcowswe | 15:9c5aaeda36dc | 1138 | }; |
madcowswe | 15:9c5aaeda36dc | 1139 | |
madcowswe | 15:9c5aaeda36dc | 1140 | |
madcowswe | 15:9c5aaeda36dc | 1141 | /** |
madcowswe | 15:9c5aaeda36dc | 1142 | * \class NumericTraits< std::complex<float> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 1143 | * \brief Traits specialized for std::complex<float>. |
madcowswe | 15:9c5aaeda36dc | 1144 | */ |
madcowswe | 15:9c5aaeda36dc | 1145 | template<> |
madcowswe | 15:9c5aaeda36dc | 1146 | struct NumericTraits< std::complex<float> > { |
madcowswe | 15:9c5aaeda36dc | 1147 | typedef float base_type; |
madcowswe | 15:9c5aaeda36dc | 1148 | typedef std::complex<float> value_type; |
madcowswe | 15:9c5aaeda36dc | 1149 | typedef std::complex<double> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1150 | typedef std::complex<float> diff_type; |
madcowswe | 15:9c5aaeda36dc | 1151 | typedef std::complex<float> float_type; |
madcowswe | 15:9c5aaeda36dc | 1152 | typedef std::complex<float> signed_type; |
madcowswe | 15:9c5aaeda36dc | 1153 | |
madcowswe | 15:9c5aaeda36dc | 1154 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 1155 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 1156 | |
madcowswe | 15:9c5aaeda36dc | 1157 | static inline |
madcowswe | 15:9c5aaeda36dc | 1158 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 1159 | |
madcowswe | 15:9c5aaeda36dc | 1160 | static inline |
madcowswe | 15:9c5aaeda36dc | 1161 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 1162 | |
madcowswe | 15:9c5aaeda36dc | 1163 | static inline |
madcowswe | 15:9c5aaeda36dc | 1164 | value_type conj(argument_type z) { return std::conj(z); } |
madcowswe | 15:9c5aaeda36dc | 1165 | |
madcowswe | 15:9c5aaeda36dc | 1166 | static inline |
madcowswe | 15:9c5aaeda36dc | 1167 | base_type abs(argument_type z) { return std::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1168 | |
madcowswe | 15:9c5aaeda36dc | 1169 | static inline |
madcowswe | 15:9c5aaeda36dc | 1170 | value_type sqrt(argument_type z) { return std::sqrt(z); } |
madcowswe | 15:9c5aaeda36dc | 1171 | |
madcowswe | 15:9c5aaeda36dc | 1172 | static inline |
madcowswe | 15:9c5aaeda36dc | 1173 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1174 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 1175 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1176 | } |
madcowswe | 15:9c5aaeda36dc | 1177 | |
madcowswe | 15:9c5aaeda36dc | 1178 | static inline |
madcowswe | 15:9c5aaeda36dc | 1179 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1180 | |
madcowswe | 15:9c5aaeda36dc | 1181 | static inline |
madcowswe | 15:9c5aaeda36dc | 1182 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1183 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 1184 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1185 | } |
madcowswe | 15:9c5aaeda36dc | 1186 | |
madcowswe | 15:9c5aaeda36dc | 1187 | static inline |
madcowswe | 15:9c5aaeda36dc | 1188 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 1189 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 1190 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1191 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 1192 | |
madcowswe | 15:9c5aaeda36dc | 1193 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 1194 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 1195 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 1196 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 1197 | } |
madcowswe | 15:9c5aaeda36dc | 1198 | |
madcowswe | 15:9c5aaeda36dc | 1199 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 1200 | |
madcowswe | 15:9c5aaeda36dc | 1201 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 1202 | enum { |
madcowswe | 15:9c5aaeda36dc | 1203 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 1204 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 1205 | }; |
madcowswe | 15:9c5aaeda36dc | 1206 | }; |
madcowswe | 15:9c5aaeda36dc | 1207 | |
madcowswe | 15:9c5aaeda36dc | 1208 | |
madcowswe | 15:9c5aaeda36dc | 1209 | /** |
madcowswe | 15:9c5aaeda36dc | 1210 | * \class NumericTraits< std::complex<double> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 1211 | * \brief Traits specialized for std::complex<double>. |
madcowswe | 15:9c5aaeda36dc | 1212 | */ |
madcowswe | 15:9c5aaeda36dc | 1213 | template<> |
madcowswe | 15:9c5aaeda36dc | 1214 | struct NumericTraits< std::complex<double> > { |
madcowswe | 15:9c5aaeda36dc | 1215 | typedef double base_type; |
madcowswe | 15:9c5aaeda36dc | 1216 | typedef std::complex<double> value_type; |
madcowswe | 15:9c5aaeda36dc | 1217 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 1218 | typedef std::complex<long double> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1219 | #else |
madcowswe | 15:9c5aaeda36dc | 1220 | typedef std::complex<double> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1221 | #endif |
madcowswe | 15:9c5aaeda36dc | 1222 | typedef std::complex<double> diff_type; |
madcowswe | 15:9c5aaeda36dc | 1223 | typedef std::complex<double> float_type; |
madcowswe | 15:9c5aaeda36dc | 1224 | typedef std::complex<double> signed_type; |
madcowswe | 15:9c5aaeda36dc | 1225 | |
madcowswe | 15:9c5aaeda36dc | 1226 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 1227 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 1228 | |
madcowswe | 15:9c5aaeda36dc | 1229 | static inline |
madcowswe | 15:9c5aaeda36dc | 1230 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 1231 | |
madcowswe | 15:9c5aaeda36dc | 1232 | static inline |
madcowswe | 15:9c5aaeda36dc | 1233 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 1234 | |
madcowswe | 15:9c5aaeda36dc | 1235 | static inline |
madcowswe | 15:9c5aaeda36dc | 1236 | value_type conj(argument_type z) { return std::conj(z); } |
madcowswe | 15:9c5aaeda36dc | 1237 | |
madcowswe | 15:9c5aaeda36dc | 1238 | static inline |
madcowswe | 15:9c5aaeda36dc | 1239 | base_type abs(argument_type z) { return std::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1240 | |
madcowswe | 15:9c5aaeda36dc | 1241 | static inline |
madcowswe | 15:9c5aaeda36dc | 1242 | value_type sqrt(argument_type z) { return std::sqrt(z); } |
madcowswe | 15:9c5aaeda36dc | 1243 | |
madcowswe | 15:9c5aaeda36dc | 1244 | static inline |
madcowswe | 15:9c5aaeda36dc | 1245 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1246 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 1247 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1248 | } |
madcowswe | 15:9c5aaeda36dc | 1249 | |
madcowswe | 15:9c5aaeda36dc | 1250 | static inline |
madcowswe | 15:9c5aaeda36dc | 1251 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1252 | |
madcowswe | 15:9c5aaeda36dc | 1253 | static inline |
madcowswe | 15:9c5aaeda36dc | 1254 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1255 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 1256 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1257 | } |
madcowswe | 15:9c5aaeda36dc | 1258 | |
madcowswe | 15:9c5aaeda36dc | 1259 | static inline |
madcowswe | 15:9c5aaeda36dc | 1260 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 1261 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 1262 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1263 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 1264 | |
madcowswe | 15:9c5aaeda36dc | 1265 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 1266 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 1267 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 1268 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 1269 | } |
madcowswe | 15:9c5aaeda36dc | 1270 | |
madcowswe | 15:9c5aaeda36dc | 1271 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 1272 | |
madcowswe | 15:9c5aaeda36dc | 1273 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 1274 | enum { |
madcowswe | 15:9c5aaeda36dc | 1275 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 1276 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 1277 | }; |
madcowswe | 15:9c5aaeda36dc | 1278 | }; |
madcowswe | 15:9c5aaeda36dc | 1279 | |
madcowswe | 15:9c5aaeda36dc | 1280 | |
madcowswe | 15:9c5aaeda36dc | 1281 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 1282 | /** |
madcowswe | 15:9c5aaeda36dc | 1283 | * \class NumericTraits< std::complex<long double> > NumericTraits.h "tvmet/NumericTraits.h" |
madcowswe | 15:9c5aaeda36dc | 1284 | * \brief Traits specialized for std::complex<double>. |
madcowswe | 15:9c5aaeda36dc | 1285 | */ |
madcowswe | 15:9c5aaeda36dc | 1286 | template<> |
madcowswe | 15:9c5aaeda36dc | 1287 | struct NumericTraits< std::complex<long double> > { |
madcowswe | 15:9c5aaeda36dc | 1288 | typedef long double base_type; |
madcowswe | 15:9c5aaeda36dc | 1289 | typedef std::complex<long double> value_type; |
madcowswe | 15:9c5aaeda36dc | 1290 | typedef std::complex<long double> sum_type; |
madcowswe | 15:9c5aaeda36dc | 1291 | typedef std::complex<long double> diff_type; |
madcowswe | 15:9c5aaeda36dc | 1292 | typedef std::complex<long double> float_type; |
madcowswe | 15:9c5aaeda36dc | 1293 | typedef std::complex<long double> signed_type; |
madcowswe | 15:9c5aaeda36dc | 1294 | |
madcowswe | 15:9c5aaeda36dc | 1295 | typedef NumericTraits<value_type> traits_type; |
madcowswe | 15:9c5aaeda36dc | 1296 | typedef const value_type& argument_type; |
madcowswe | 15:9c5aaeda36dc | 1297 | |
madcowswe | 15:9c5aaeda36dc | 1298 | static inline |
madcowswe | 15:9c5aaeda36dc | 1299 | base_type real(argument_type z) { return std::real(z); } |
madcowswe | 15:9c5aaeda36dc | 1300 | |
madcowswe | 15:9c5aaeda36dc | 1301 | static inline |
madcowswe | 15:9c5aaeda36dc | 1302 | base_type imag(argument_type z) { return std::imag(z); } |
madcowswe | 15:9c5aaeda36dc | 1303 | |
madcowswe | 15:9c5aaeda36dc | 1304 | static inline |
madcowswe | 15:9c5aaeda36dc | 1305 | value_type conj(argument_type z) { return std::conj(z); } |
madcowswe | 15:9c5aaeda36dc | 1306 | |
madcowswe | 15:9c5aaeda36dc | 1307 | static inline |
madcowswe | 15:9c5aaeda36dc | 1308 | base_type abs(argument_type z) { return std::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1309 | |
madcowswe | 15:9c5aaeda36dc | 1310 | static inline |
madcowswe | 15:9c5aaeda36dc | 1311 | value_type sqrt(argument_type z) { return std::sqrt(z); } |
madcowswe | 15:9c5aaeda36dc | 1312 | |
madcowswe | 15:9c5aaeda36dc | 1313 | static inline |
madcowswe | 15:9c5aaeda36dc | 1314 | base_type norm_1(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1315 | return NumericTraits<base_type>::abs((traits_type::real(z))) |
madcowswe | 15:9c5aaeda36dc | 1316 | + NumericTraits<base_type>::abs((traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1317 | } |
madcowswe | 15:9c5aaeda36dc | 1318 | |
madcowswe | 15:9c5aaeda36dc | 1319 | static inline |
madcowswe | 15:9c5aaeda36dc | 1320 | base_type norm_2(argument_type z) { return traits_type::abs(z); } |
madcowswe | 15:9c5aaeda36dc | 1321 | |
madcowswe | 15:9c5aaeda36dc | 1322 | static inline |
madcowswe | 15:9c5aaeda36dc | 1323 | base_type norm_inf(argument_type z) { |
madcowswe | 15:9c5aaeda36dc | 1324 | return std::max(NumericTraits<base_type>::abs(traits_type::real(z)), |
madcowswe | 15:9c5aaeda36dc | 1325 | NumericTraits<base_type>::abs(traits_type::imag(z))); |
madcowswe | 15:9c5aaeda36dc | 1326 | } |
madcowswe | 15:9c5aaeda36dc | 1327 | |
madcowswe | 15:9c5aaeda36dc | 1328 | static inline |
madcowswe | 15:9c5aaeda36dc | 1329 | bool equals(argument_type lhs, argument_type rhs) { |
madcowswe | 15:9c5aaeda36dc | 1330 | static base_type sqrt_epsilon( |
madcowswe | 15:9c5aaeda36dc | 1331 | NumericTraits<base_type>::sqrt( |
madcowswe | 15:9c5aaeda36dc | 1332 | std::numeric_limits<base_type>::epsilon())); |
madcowswe | 15:9c5aaeda36dc | 1333 | |
madcowswe | 15:9c5aaeda36dc | 1334 | return traits_type::norm_inf(lhs - rhs) < sqrt_epsilon * |
madcowswe | 15:9c5aaeda36dc | 1335 | std::max(std::max(traits_type::norm_inf(lhs), |
madcowswe | 15:9c5aaeda36dc | 1336 | traits_type::norm_inf(rhs)), |
madcowswe | 15:9c5aaeda36dc | 1337 | std::numeric_limits<base_type>::min()); |
madcowswe | 15:9c5aaeda36dc | 1338 | } |
madcowswe | 15:9c5aaeda36dc | 1339 | |
madcowswe | 15:9c5aaeda36dc | 1340 | enum { is_complex = true }; |
madcowswe | 15:9c5aaeda36dc | 1341 | |
madcowswe | 15:9c5aaeda36dc | 1342 | /** Complexity on operations. */ |
madcowswe | 15:9c5aaeda36dc | 1343 | enum { |
madcowswe | 15:9c5aaeda36dc | 1344 | ops_plus = 2, /**< Complexity on plus/minus ops. */ |
madcowswe | 15:9c5aaeda36dc | 1345 | ops_muls = 6 /**< Complexity on multiplications. */ |
madcowswe | 15:9c5aaeda36dc | 1346 | }; |
madcowswe | 15:9c5aaeda36dc | 1347 | }; |
madcowswe | 15:9c5aaeda36dc | 1348 | #endif // defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 15:9c5aaeda36dc | 1349 | |
madcowswe | 15:9c5aaeda36dc | 1350 | |
madcowswe | 15:9c5aaeda36dc | 1351 | #endif // defined(TVMET_HAVE_COMPLEX) |
madcowswe | 15:9c5aaeda36dc | 1352 | |
madcowswe | 15:9c5aaeda36dc | 1353 | |
madcowswe | 15:9c5aaeda36dc | 1354 | } // namespace tvmet |
madcowswe | 15:9c5aaeda36dc | 1355 | |
madcowswe | 15:9c5aaeda36dc | 1356 | |
madcowswe | 15:9c5aaeda36dc | 1357 | #endif // TVMET_NUMERIC_TRAITS_H |
madcowswe | 15:9c5aaeda36dc | 1358 | |
madcowswe | 15:9c5aaeda36dc | 1359 | |
madcowswe | 15:9c5aaeda36dc | 1360 | // Local Variables: |
madcowswe | 15:9c5aaeda36dc | 1361 | // mode:C++ |
madcowswe | 15:9c5aaeda36dc | 1362 | // tab-width:8 |
madcowswe | 15:9c5aaeda36dc | 1363 | // End: |