5 #ifndef USML_UBLAS_MATH_TRAITS_HH
6 #define USML_UBLAS_MATH_TRAITS_HH
10 #include<boost/numeric/ublas/vector.hpp>
11 #include<boost/numeric/ublas/matrix.hpp>
12 #include<boost/numeric/ublas/io.hpp>
13 #include <usml/usml_config.h>
15 # define TWO_PI (2.0*M_PI)
21 using std::operator<<;
53 using namespace boost::numeric::ublas;
55 const complex<double>
DOUBLE_I = complex<double> (0.0, 1.0);
56 const complex<float>
FLOAT_I = complex<float> (0.0, 1.0);
146 return std::max(t1, t2);
150 return std::min(t1, t2);
154 return std::floor(t);
166 return t * (180.0 / M_PI);
171 return t * (M_PI / 180.0);
193 return ( t2 < 0.0 ) ? -t1 : t1 ;
235 return log(t +
sqrt(t * t - 1.0));
243 return log(t +
sqrt(t * t + 1.0));
251 return std::atan2(y, x);
255 return 0.5 *
log((1.0 + t) / (1.0 - t));
271 return std::log10(t);
275 return std::pow(t, e);
279 return std::pow(t, e);
308 return t.real() * t.real() + t.imag() * t.imag();
330 return std::max(t1, t2);
334 return std::min(t1, t2);
338 return std::floor(t);
350 return t * (180.0 / M_PI);
355 return t * (M_PI / 180.0);
377 return ( t2 < 0.0 ) ? -t1 : t1 ;
419 return log(t +
sqrt(t * t - 1.0f));
427 return log(t +
sqrt(t * t + 1.0f));
435 return std::atan2(y, x);
439 return 0.5 *
log((1.0f + t) / (1.0f - t));
455 return std::log10(t);
459 return std::pow(t, e);
463 return std::pow(t, e);
492 return t.real() * t.real() + t.imag() * t.imag();
556 return log(t +
sqrt(t * t - 1.0));
564 return log(t +
sqrt(t * t + 1.0));
577 return 0.5 *
log((1.0 + t) / (1.0 - t));
593 return std::log10(t);
597 return std::pow(t, e);
601 return std::pow(t, e);
609 return std::pow(t, e);
613 return std::pow(t, e);
678 return log(t +
sqrt(t * t - 1.0f));
686 return log(t +
sqrt(t * t + 1.0f));
699 return 0.5f *
log((1.0f + t) / (1.0f - t));
715 return std::log10(t);
719 return std::pow(t, e);
723 return std::pow(t, e);
731 return std::pow(t, e);
735 return std::pow(t, e);
770 #ifdef _MSC_VER // Microsoft Visual C++
772 #define NAN std::numeric_limits<double>::quiet_NaN()
774 inline int isnan(
double x) {
return _isnan(x); }
775 inline int round(
double x) {
return floor(x + 0.5); }
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_cos< typename E::value_type > >::result_type cos(const matrix_expression< E > &e)
Cosine of a matrix.
Definition: matrix_math.h:328
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_cosh< typename E::value_type > >::result_type cosh(const matrix_expression< E > &e)
Hyperbolic cosine of a matrix.
Definition: matrix_math.h:341
static value_type pow(const_reference t, int e)
Definition: math_traits.h:595
static value_type asin(const_reference t)
Definition: math_traits.h:558
math_traits< double >::value_type to_colatitude(math_traits< double >::const_reference t)
Definition: math_traits.h:761
static value_type exp(const_reference t)
Definition: math_traits.h:705
complex< double > & reference
Definition: math_traits.h:507
const complex< float > FLOAT_I
Definition: math_traits.h:56
static value_type atan2(const_reference y, const_reference x)
Definition: math_traits.h:693
BOOST_UBLAS_INLINE matrix_binary_traits< E1, E2, scalar_atan2< typename E1::value_type, typename E2::value_type > >::result_type atan2(const matrix_expression< E1 > &y, const matrix_expression< E2 > &x)
Inverse tangent of matrix y / matrix x.
Definition: matrix_math.h:474
const complex< double > DOUBLE_I
Definition: math_traits.h:55
static value_type atanh(const_reference t)
Definition: math_traits.h:437
static value_type log10(const_reference t)
Definition: math_traits.h:713
static value_type atan2(const_reference y, const_reference x)
Definition: math_traits.h:571
static value_type sqrt(const_reference t)
Definition: math_traits.h:513
static real_type abs2(const complex< value_type > &t)
Definition: math_traits.h:490
float value_type
Definition: math_traits.h:320
Definition: math_traits.h:76
static value_type cos(const_reference t)
Definition: math_traits.h:383
static value_type asinh(const_reference t)
Definition: math_traits.h:425
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_asinh< typename E::value_type > >::result_type asinh(const matrix_expression< E > &e)
Inverse hyperbolic sine of a matrix.
Definition: matrix_math.h:448
math_traits< double >::value_type to_latitude(math_traits< double >::const_reference t)
Definition: math_traits.h:755
static real_type abs(const_reference t)
Definition: math_traits.h:285
static value_type atan2(const_reference y, const_reference x)
Definition: math_traits.h:249
static value_type to_degrees(const_reference t)
Definition: math_traits.h:348
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_floor< typename E::value_type > >::result_type floor(const matrix_expression< E > &e)
Rounding elements of a matrix down to the nearest integer.
Definition: matrix_math.h:170
static value_type min(const_reference t1, const_reference t2)
Definition: math_traits.h:148
T & reference
Definition: math_traits.h:81
static value_type log(const_reference t)
Definition: math_traits.h:709
static value_type tan(const_reference t)
Definition: math_traits.h:399
static value_type asinh(const_reference t)
Definition: math_traits.h:684
static value_type asinh(const_reference t)
Definition: math_traits.h:241
static value_type exp(const_reference t)
Definition: math_traits.h:445
static value_type to_latitude(const_reference t)
Definition: math_traits.h:174
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_exp< typename E::value_type > >::result_type exp(const matrix_expression< E > &e)
Exponential of a matrix.
Definition: matrix_math.h:503
static value_type asin(const_reference t)
Definition: math_traits.h:680
static value_type asin(const_reference t)
Definition: math_traits.h:421
static value_type acos(const_reference t)
Definition: math_traits.h:413
math_traits< double > self_type
Definition: math_traits.h:135
static real_type arg(const complex< value_type > &t)
Definition: math_traits.h:486
static value_type tanh(const_reference t)
Definition: math_traits.h:219
static value_type log(const_reference t)
Definition: math_traits.h:587
static real_type abs(const complex< value_type > &t)
Definition: math_traits.h:482
static value_type pow(const_reference t, const_reference e)
Definition: math_traits.h:599
static value_type log(const_reference t)
Definition: math_traits.h:449
static real_type arg(const_reference t)
Definition: math_traits.h:289
static value_type cosh(const_reference t)
Definition: math_traits.h:203
static value_type cos(const_reference t)
Definition: math_traits.h:199
static value_type to_radians(const_reference t)
Definition: math_traits.h:353
static value_type to_colatitude(const_reference t)
Definition: math_traits.h:179
static value_type to_degrees(const_reference t)
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_tan< typename E::value_type > >::result_type tan(const matrix_expression< E > &e)
Tangent of a matrix.
Definition: matrix_math.h:380
math_traits< float > self_type
Definition: math_traits.h:319
T value_type
Definition: math_traits.h:79
static value_type atan(const_reference t)
Definition: math_traits.h:429
static value_type copysign(const_reference t1, const_reference t2)
Definition: math_traits.h:375
static value_type ceil(const_reference t)
Definition: math_traits.h:340
static value_type pow(const_reference t, int e)
Definition: math_traits.h:273
static value_type sin(const_reference t)
Definition: math_traits.h:207
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_sinh< typename E::value_type > >::result_type sinh(const matrix_expression< E > &e)
Hyperbolic sine of a matrix.
Definition: matrix_math.h:367
double real_type
Definition: math_traits.h:508
BOOST_UBLAS_INLINE boost::enable_if< boost::is_convertible< T2, typename E1::value_type >, typename matrix_binary_scalar2_traits< E1, const T2, scalar_pow< typename E1::value_type, T2 > >::result_type >::type pow(const matrix_expression< E1 > &e1, const T2 &e2)
Raise matrix (v) to a scalar (t) power such that (v^t)[i] = v[i] ^ t.
Definition: matrix_math.h:544
static value_type log10(const_reference t)
Definition: math_traits.h:453
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_atan< typename E::value_type > >::result_type atan(const matrix_expression< E > &e)
Inverse tangent of a matrix.
Definition: matrix_math.h:461
static value_type to_latitude(const_reference t)
Definition: math_traits.h:358
complex< double > value_type
Definition: math_traits.h:505
math_traits< complex< float > > self_type
Definition: math_traits.h:626
const complex< double > & const_reference
Definition: math_traits.h:506
static value_type atan2(const_reference y, const_reference x)
Definition: math_traits.h:433
static real_type arg(const complex< value_type > &t)
Definition: math_traits.h:302
static value_type pow(const_reference t, int e)
Definition: math_traits.h:717
static value_type tanh(const_reference t)
Definition: math_traits.h:540
static value_type acosh(const_reference t)
Definition: math_traits.h:554
static real_type arg(const_reference t)
Definition: math_traits.h:473
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_acos< typename E::value_type > >::result_type acos(const matrix_expression< E > &e)
Inverse cosine of a matrix.
Definition: matrix_math.h:409
Definition: math_traits.h:133
const double & const_reference
Definition: math_traits.h:137
static value_type sinh(const_reference t)
Definition: math_traits.h:211
math_traits< T > self_type
Definition: math_traits.h:78
static value_type tanh(const_reference t)
Definition: math_traits.h:662
static value_type atanh(const_reference t)
Definition: math_traits.h:697
static value_type sinh(const_reference t)
Definition: math_traits.h:654
float real_type
Definition: math_traits.h:323
static value_type to_degrees(const_reference t)
Definition: math_traits.h:164
double & reference
Definition: math_traits.h:138
static value_type floor(const_reference t)
Definition: math_traits.h:152
static value_type max(const_reference t1, const_reference t2)
Definition: math_traits.h:328
static value_type asinh(const_reference t)
Definition: math_traits.h:562
const float & const_reference
Definition: math_traits.h:321
static real_type abs2(const_reference t)
Definition: math_traits.h:477
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_asin< typename E::value_type > >::result_type asin(const matrix_expression< E > &e)
Inverse sine of a matrix.
Definition: matrix_math.h:435
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_tanh< typename E::value_type > >::result_type tanh(const matrix_expression< E > &e)
Hyperbolic tangent of a matrix.
Definition: matrix_math.h:393
static real_type abs2(const complex< value_type > &t)
Definition: math_traits.h:306
static value_type acosh(const_reference t)
Definition: math_traits.h:676
T real_type
Definition: math_traits.h:82
static value_type cos(const_reference t)
Definition: math_traits.h:642
static value_type exp(const_reference t)
Definition: math_traits.h:583
static value_type sin(const_reference t)
Definition: math_traits.h:650
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_acosh< typename E::value_type > >::result_type acosh(const matrix_expression< E > &e)
Inverse hyperbolic cosine of a matrix.
Definition: matrix_math.h:422
static value_type asin(const_reference t)
Definition: math_traits.h:237
static real_type abs(const_reference t)
Definition: math_traits.h:469
static value_type sqrt(const_reference t)
Definition: math_traits.h:371
static value_type pow(real_type t, const_reference e)
Definition: math_traits.h:733
static value_type sin(const_reference t)
Definition: math_traits.h:391
static value_type pow(const_reference t, real_type e)
Definition: math_traits.h:729
math_traits< complex< double > > self_type
Definition: math_traits.h:504
float & reference
Definition: math_traits.h:322
complex< float > & reference
Definition: math_traits.h:629
static value_type tanh(const_reference t)
Definition: math_traits.h:403
static value_type ceil(const_reference t)
Definition: math_traits.h:156
static value_type max(const_reference t1, const_reference t2)
Definition: math_traits.h:144
static value_type to_radians(const_reference t)
Definition: math_traits.h:169
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_sin< typename E::value_type > >::result_type sin(const matrix_expression< E > &e)
Sine of a matrix.
Definition: matrix_math.h:354
static value_type asinh(const_reference t)
static value_type to_latitude(const_reference t)
static value_type pow(const_reference t, const_reference e)
Definition: math_traits.h:461
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_log10< typename E::value_type > >::result_type log10(const matrix_expression< E > &e)
Base 10 logarithm of a matrix.
Definition: matrix_math.h:529
static value_type pow(const_reference t, real_type e)
Definition: math_traits.h:607
static value_type atanh(const_reference t)
Definition: math_traits.h:575
static value_type tan(const_reference t)
Definition: math_traits.h:215
static real_type abs(const complex< value_type > &t)
Definition: math_traits.h:298
static value_type log10(const_reference t)
Definition: math_traits.h:269
double real_type
Definition: math_traits.h:139
static value_type to_colatitude(const_reference t)
Definition: math_traits.h:363
static value_type cosh(const_reference t)
Definition: math_traits.h:524
static value_type atan(const_reference t)
Definition: math_traits.h:566
static value_type exp(const_reference t)
Definition: math_traits.h:261
const T & const_reference
Definition: math_traits.h:80
static value_type to_radians(const_reference t)
static value_type pow(const_reference t, int e)
Definition: math_traits.h:457
static value_type tan(const_reference t)
Definition: math_traits.h:658
static value_type copysign(const_reference t1, const_reference t2)
Definition: math_traits.h:191
float real_type
Definition: math_traits.h:630
static value_type cos(const_reference t)
Definition: math_traits.h:520
static real_type abs2(const_reference t)
Definition: math_traits.h:293
static value_type tan(const_reference t)
Definition: math_traits.h:536
double value_type
Definition: math_traits.h:136
static value_type atan(const_reference t)
Definition: math_traits.h:245
static value_type acos(const_reference t)
Definition: math_traits.h:229
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_log< typename E::value_type > >::result_type log(const matrix_expression< E > &e)
Natural logarithm of a matrix.
Definition: matrix_math.h:516
math_traits< double >::value_type to_degrees(math_traits< double >::const_reference t)
Definition: math_traits.h:743
static value_type acosh(const_reference t)
Definition: math_traits.h:233
static value_type sinh(const_reference t)
Definition: math_traits.h:395
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_atanh< typename E::value_type > >::result_type atanh(const matrix_expression< E > &e)
Inverse hyperbolic tangent of a matrix.
Definition: matrix_math.h:487
static value_type pow(real_type t, const_reference e)
Definition: math_traits.h:611
static value_type acosh(const_reference t)
Definition: math_traits.h:417
static value_type to_colatitude(const_reference t)
static value_type log(const_reference t)
Definition: math_traits.h:265
const complex< float > & const_reference
Definition: math_traits.h:628
static value_type pow(const_reference t, const_reference e)
Definition: math_traits.h:277
static value_type acos(const_reference t)
Definition: math_traits.h:550
static value_type atanh(const_reference t)
complex< float > value_type
Definition: math_traits.h:627
static value_type atan(const_reference t)
Definition: math_traits.h:688
static value_type cosh(const_reference t)
Definition: math_traits.h:646
static value_type cosh(const_reference t)
Definition: math_traits.h:387
static value_type log10(const_reference t)
Definition: math_traits.h:591
Definition: math_traits.h:317
static value_type min(const_reference t1, const_reference t2)
Definition: math_traits.h:332
static value_type atanh(const_reference t)
Definition: math_traits.h:253
static value_type sqrt(const_reference t)
Definition: math_traits.h:187
static value_type pow(const_reference t, const_reference e)
Definition: math_traits.h:721
math_traits< double >::value_type to_radians(math_traits< double >::const_reference t)
Definition: math_traits.h:749
static value_type acosh(const_reference t)
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_sqrt< typename E::value_type > >::result_type sqrt(const matrix_expression< E > &e)
Square root of a matrix.
Definition: matrix_math.h:296
static value_type sin(const_reference t)
Definition: math_traits.h:528
static value_type sqrt(const_reference t)
Definition: math_traits.h:635
static value_type floor(const_reference t)
Definition: math_traits.h:336
static value_type acos(const_reference t)
Definition: math_traits.h:672
static value_type sinh(const_reference t)
Definition: math_traits.h:532