working version with calibration done

Fork of Eurobot2013 by Oskar Weigl

Committer:
xiaxia686
Date:
Tue Apr 09 15:32:47 2013 +0000
Revision:
11:5ba926692210
Parent:
1:6799c07fe510
woking version (calibrated)

Who changed what in which revision?

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