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