glucat  0.8.4
scalar.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_SCALAR_H
2 #define _GLUCAT_SCALAR_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  scalar.h : Define functions for scalar_t
6  -------------------
7  begin : 2001-12-20
8  copyright : (C) 2001-2016 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations, Birkhauser, 1996."
30  ***************************************************************************
31  See also Arvind Raja's original header comments and references in glucat.h
32  ***************************************************************************/
33 
34 #include "glucat/portability.h"
35 
36 #include <boost/numeric/ublas/traits.hpp>
37 
38 #include <cmath>
39 #include <limits>
40 
41 namespace glucat
42 {
44  // Reference: [AA], 2.4, p. 30-31
45  template< typename Scalar_T >
46  class numeric_traits
47  {
48  private:
50  inline
51  static
52  bool
53  isInf(const Scalar_T& val, bool_to_type<false>)
54  { return false; }
55 
57  inline
58  static
59  bool
60  isInf(const Scalar_T& val, bool_to_type<true>)
61  { return _GLUCAT_ISINF(val); }
62 
64  inline
65  static
66  bool
67  isNaN(const Scalar_T& val, bool_to_type<false>)
68  { return false; }
69 
71  inline
72  static
73  bool
74  isNaN(const Scalar_T& val, bool_to_type<true>)
75  { return _GLUCAT_ISNAN(val); }
76 
77  public:
79  inline
80  static
81  bool
82  isInf(const Scalar_T& val)
83  {
84  return isInf(val,
85  bool_to_type< std::numeric_limits<Scalar_T>::has_infinity >() );
86  }
87 
89  inline
90  static
91  bool
92  isNaN(const Scalar_T& val)
93  {
94  return isNaN(val,
95  bool_to_type< std::numeric_limits<Scalar_T>::has_quiet_NaN >() );
96  }
97 
99  inline
100  static
101  bool
102  isNaN_or_isInf(const Scalar_T& val)
103  {
104  return isNaN(val,
105  bool_to_type< std::numeric_limits<Scalar_T>::has_quiet_NaN >() )
106  || isInf(val,
107  bool_to_type< std::numeric_limits<Scalar_T>::has_infinity >() );
108  }
109 
111  inline
112  static
113  Scalar_T
114  NaN()
115  {
116  return std::numeric_limits<Scalar_T>::has_quiet_NaN
117  ? std::numeric_limits<Scalar_T>::quiet_NaN()
118  : Scalar_T(std::log(0.0));
119  }
120 
122  inline
123  static
124  int
125  to_int(const Scalar_T& val)
126  { return static_cast<int>(val); }
127 
129  inline
130  static
131  double
132  to_double(const Scalar_T& val)
133  { return static_cast<double>(val); }
134 
136  template <typename Other_Scalar_T >
137  inline
138  static
139  Scalar_T
140  to_scalar_t(const Other_Scalar_T& val)
141  { return static_cast<Scalar_T>(val); }
142 
144  struct promoted {typedef double type;};
145 
147  struct demoted {typedef float type;};
148 
150  inline
151  static
152  Scalar_T
153  fmod(const Scalar_T& lhs, const Scalar_T& rhs)
154  { return std::fmod(lhs, rhs); }
155 
157  inline
158  static
159  Scalar_T
160  conj(const Scalar_T& val)
161  { return val; }
162 
164  inline
165  static
166  Scalar_T
167  real(const Scalar_T& val)
168  { return val; }
169 
171  inline
172  static
173  Scalar_T
174  imag(const Scalar_T& val)
175  { return Scalar_T(0); }
176 
178  inline
179  static
180  Scalar_T
181  abs(const Scalar_T& val)
183 
185  inline
186  static
187  Scalar_T
188  pi()
189  { return Scalar_T(3.14159265358979323); }
190 
192  inline
193  static
194  Scalar_T
195  ln_2()
196  { return Scalar_T(0.693147180559945309); }
197 
199  inline
200  static
201  Scalar_T
202  pow(const Scalar_T& val, int n)
203  { return std::pow(val, n); }
204 
206  inline
207  static
208  Scalar_T
209  sqrt(const Scalar_T& val)
211 
213  inline
214  static
215  Scalar_T
216  exp(const Scalar_T& val)
217  { return std::exp(val); }
218 
220  inline
221  static
222  Scalar_T
223  log(const Scalar_T& val)
224  { return std::log(val); }
225 
227  inline
228  static
229  Scalar_T
230  log2(const Scalar_T& val)
231  { return log(val)/ln_2(); }
232 
234  inline
235  static
236  Scalar_T
237  cos(const Scalar_T& val)
238  { return std::cos(val); }
239 
241  inline
242  static
243  Scalar_T
244  acos(const Scalar_T& val)
245  { return std::acos(val); }
246 
248  inline
249  static
250  Scalar_T
251  cosh(const Scalar_T& val)
252  { return std::cosh(val); }
253 
255  inline
256  static
257  Scalar_T
258  sin(const Scalar_T& val)
259  { return std::sin(val); }
260 
262  inline
263  static
264  Scalar_T
265  asin(const Scalar_T& val)
266  { return std::asin(val); }
267 
269  inline
270  static
271  Scalar_T
272  sinh(const Scalar_T& val)
273  { return std::sinh(val); }
274 
276  inline
277  static
278  Scalar_T
279  tan(const Scalar_T& val)
280  { return std::tan(val); }
281 
283  inline
284  static
285  Scalar_T
286  atan(const Scalar_T& val)
287  { return std::atan(val); }
288 
290  inline
291  static
292  Scalar_T
293  tanh(const Scalar_T& val)
294  { return std::tanh(val); }
295 
296  };
297 
299  template< typename Scalar_T >
300  inline
301  Scalar_T
302  log2(const Scalar_T& x)
303  { return numeric_traits<Scalar_T>::log2(x); }
304 }
305 
306 #endif // _GLUCAT_SCALAR_H
glucat::numeric_traits::imag
static Scalar_T imag(const Scalar_T &val)
Imaginary part of scalar.
Definition: scalar.h:232
glucat::numeric_traits::conj
static Scalar_T conj(const Scalar_T &val)
Complex conjugate of scalar.
Definition: scalar.h:218
glucat::numeric_traits::log2
static Scalar_T log2(const Scalar_T &val)
Log base 2.
Definition: scalar.h:288
glucat::asin
const Multivector< Scalar_T, LO, HI > asin(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Inverse sine of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:934
_GLUCAT_ISNAN
#define _GLUCAT_ISNAN(x)
Definition: portability.h:47
portability.h
glucat::numeric_traits::cos
static Scalar_T cos(const Scalar_T &val)
Cosine of scalar.
Definition: scalar.h:295
UBLAS_ABS
#define UBLAS_ABS
Definition: portability.h:56
glucat::numeric_traits::atan
static Scalar_T atan(const Scalar_T &val)
Inverse tangent of scalar.
Definition: scalar.h:344
glucat::numeric_traits::isNaN_or_isInf
static bool isNaN_or_isInf(const Scalar_T &val)
Smart isnan or isinf.
Definition: scalar.h:160
_GLUCAT_ISINF
#define _GLUCAT_ISINF(x)
Definition: portability.h:48
glucat::numeric_traits::pow
static Scalar_T pow(const Scalar_T &val, int n)
Integer power.
Definition: scalar.h:260
glucat::atan
const Multivector< Scalar_T, LO, HI > atan(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Inverse tangent of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:1034
glucat::numeric_traits::exp
static Scalar_T exp(const Scalar_T &val)
Exponential.
Definition: scalar.h:274
glucat::tan
const Multivector< Scalar_T, LO, HI > tan(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Tangent of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:1006
glucat::numeric_traits::demoted::type
long double type
Definition: long_double.h:78
glucat::numeric_traits::fmod
static Scalar_T fmod(const Scalar_T &lhs, const Scalar_T &rhs)
Modulo function for scalar.
Definition: scalar.h:211
glucat::numeric_traits::tanh
static Scalar_T tanh(const Scalar_T &val)
Hyperbolic tangent of scalar.
Definition: scalar.h:351
glucat::numeric_traits::isInf
static bool isInf(const Scalar_T &val, bool_to_type< false >)
Smart isinf specialised for Scalar_T without infinity.
Definition: scalar.h:111
glucat::acos
const Multivector< Scalar_T, LO, HI > acos(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Inverse cosine of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:827
glucat::cosh
const Multivector< Scalar_T, LO, HI > cosh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic cosine of multivector.
Definition: clifford_algebra_imp.h:749
glucat::numeric_traits::acos
static Scalar_T acos(const Scalar_T &val)
Inverse cosine of scalar.
Definition: scalar.h:302
glucat::numeric_traits::sin
static Scalar_T sin(const Scalar_T &val)
Sine of scalar.
Definition: scalar.h:316
glucat::numeric_traits::pi
static Scalar_T pi()
Pi.
Definition: scalar.h:246
glucat::numeric_traits::NaN
static Scalar_T NaN()
Smart NaN.
Definition: scalar.h:172
glucat::numeric_traits::to_int
static int to_int(const Scalar_T &val)
Cast to int.
Definition: scalar.h:183
glucat::sinh
const Multivector< Scalar_T, LO, HI > sinh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic sine of multivector.
Definition: clifford_algebra_imp.h:855
UBLAS_SQRT
#define UBLAS_SQRT
Definition: portability.h:57
glucat::numeric_traits::ln_2
static Scalar_T ln_2()
log(2)
Definition: scalar.h:253
glucat::numeric_traits::to_scalar_t
static Scalar_T to_scalar_t(const Other_Scalar_T &val)
Cast to Scalar_T.
Definition: scalar.h:198
glucat::numeric_traits::asin
static Scalar_T asin(const Scalar_T &val)
Inverse sine of scalar.
Definition: scalar.h:323
glucat::numeric_traits::log
static Scalar_T log(const Scalar_T &val)
Logarithm of scalar.
Definition: scalar.h:281
glucat::log
const Multivector< Scalar_T, LO, HI > log(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Natural logarithm of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:733
glucat::numeric_traits::to_double
static double to_double(const Scalar_T &val)
Cast to double.
Definition: scalar.h:190
std
Definition: framed_multi.h:371
glucat
Definition: clifford_algebra.h:39
glucat::numeric_traits::isNaN
static bool isNaN(const Scalar_T &val, bool_to_type< false >)
Smart isnan specialised for Scalar_T without quiet NaN.
Definition: scalar.h:125
glucat::numeric_traits::real
static Scalar_T real(const Scalar_T &val)
Real part of scalar.
Definition: scalar.h:225
glucat::pow
const Multivector< Scalar_T, LO, HI > pow(const Multivector< Scalar_T, LO, HI > &lhs, int rhs)
Integer power of multivector.
Definition: clifford_algebra_imp.h:357
glucat::bool_to_type
Bool to type.
Definition: global.h:99
glucat::sin
const Multivector< Scalar_T, LO, HI > sin(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Sine of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:901
glucat::numeric_traits::tan
static Scalar_T tan(const Scalar_T &val)
Tangent of scalar.
Definition: scalar.h:337
glucat::numeric_traits::sqrt
static Scalar_T sqrt(const Scalar_T &val)
Square root of scalar.
Definition: scalar.h:267
glucat::numeric_traits::sinh
static Scalar_T sinh(const Scalar_T &val)
Hyperbolic sine of scalar.
Definition: scalar.h:330
glucat::cos
const Multivector< Scalar_T, LO, HI > cos(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Cosine of multivector with specified complexifier.
Definition: clifford_algebra_imp.h:794
glucat::exp
const framed_multi< Scalar_T, LO, HI > exp(const framed_multi< Scalar_T, LO, HI > &val)
Exponential of multivector.
Definition: framed_multi_imp.h:1977
glucat::log2
Scalar_T log2(const Scalar_T &x)
Log base 2 of scalar.
Definition: scalar.h:331
glucat::tanh
const Multivector< Scalar_T, LO, HI > tanh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic tangent of multivector.
Definition: clifford_algebra_imp.h:962
glucat::numeric_traits::promoted::type
double type
Definition: scalar.h:202
glucat::numeric_traits::cosh
static Scalar_T cosh(const Scalar_T &val)
Hyperbolic cosine of scalar.
Definition: scalar.h:309
glucat::numeric_traits::abs
static Scalar_T abs(const Scalar_T &val)
Absolute value of scalar.
Definition: scalar.h:239