glucat  0.8.2
qd.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_QD_H
2 #define _GLUCAT_QD_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  qd.h : Define functions for dd_real and qd_real as scalar_t
6  -------------------
7  begin : 2010-03-23
8  copyright : (C) 2010-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/scalar.h"
35 
36 #if defined(_GLUCAT_USE_QD)
37 # include <qd/qd_real.h>
38 # if defined(QD_API)
39 
40 namespace glucat
41 {
43  // Reference: [AA], 2.4, p. 30-31
44 
46  template<>
47  struct
48  numeric_traits<double>::
49  promoted {typedef dd_real type;};
50 
52  template<>
53  struct
54  numeric_traits<long double>::
55  promoted {typedef dd_real type;};
56 
57 #define _GLUCAT_QD_F(_T, _F) \
58  template<> \
59  inline \
60  _T \
61  numeric_traits<_T>:: \
62  _F(const _T& val) \
63  { return ::_F(val); }
64 
66  template<>
67  inline
68  bool
70  isNaN(const dd_real& val)
71  { return val.isnan(); }
72 
74  template<>
75  inline
76  bool
78  isInf(const dd_real& val)
79  { return val.isinf(); }
80 
82  template<>
83  inline
84  bool
86  isNaN_or_isInf(const dd_real& val)
87  { return val.isnan() || val.isinf(); }
88 
90  template<>
91  inline
92  int
94  to_int(const dd_real& val)
95  { return ::to_int(val); }
96 
98  template<>
99  inline
100  double
102  to_double(const dd_real& val)
103  { return ::to_double(val); }
104 
106  template<>
107  struct
108  numeric_traits<dd_real>::
109  promoted {typedef qd_real type;};
110 
112  template<>
113  struct
114  numeric_traits<dd_real>::
115  demoted {typedef double type;};
116 
118  template<>
119  inline
120  dd_real
122  fmod(const dd_real& lhs, const dd_real& rhs)
123  { return ::fmod(lhs, rhs); }
124 
126  template<>
127  inline
128  dd_real
130  pow(const dd_real& val, int n)
131  {
132  dd_real result = 1.0;
133  dd_real pow2 = val;
134  for (int k = n; k != 0; pow2 *= pow2, k /= 2)
135  if (k % 2)
136  result *= pow2;
137  return result;
138  }
139 
141  template<>
142  inline
143  dd_real
145  pi()
146  { return dd_real::_pi; }
147 
149  template<>
150  inline
151  dd_real
153  ln_2()
154  { return dd_real::_log2; }
155 
157  _GLUCAT_QD_F(dd_real, exp)
158 
159 
160  _GLUCAT_QD_F(dd_real, log)
161 
163  _GLUCAT_QD_F(dd_real, cos)
164 
166  _GLUCAT_QD_F(dd_real, acos)
167 
169  _GLUCAT_QD_F(dd_real, cosh)
170 
172  _GLUCAT_QD_F(dd_real, sin)
173 
175  _GLUCAT_QD_F(dd_real, asin)
176 
178  _GLUCAT_QD_F(dd_real, sinh)
179 
181  _GLUCAT_QD_F(dd_real, tan)
182 
184  _GLUCAT_QD_F(dd_real, atan)
185 
187  _GLUCAT_QD_F(dd_real, tanh)
188 
190  template<>
191  inline
192  bool
193  numeric_traits<qd_real>::
194  isNaN(const qd_real& val)
195  { return val.isnan(); }
196 
198  template<>
199  inline
200  bool
202  isInf(const qd_real& val)
203  { return val.isinf(); }
204 
206  template<>
207  inline
208  bool
210  isNaN_or_isInf(const qd_real& val)
211  { return val.isnan() || val.isinf(); }
212 
214  template<>
215  inline
216  int
218  to_int(const qd_real& val)
219  { return ::to_int(val); }
220 
222  template<>
223  inline
224  double
226  to_double(const qd_real& val)
227  { return ::to_double(val); }
228 
230  template<>
231  struct
232  numeric_traits<qd_real>::
233  promoted {typedef qd_real type;};
234 
236  template<>
237  struct
238  numeric_traits<qd_real>::
239  demoted {typedef qd_real type;};
240 
242  template<>
243  inline
244  qd_real
246  fmod(const qd_real& lhs, const qd_real& rhs)
247  { return ::fmod(lhs, rhs); }
248 
250  template<>
251  inline
252  qd_real
254  pow(const qd_real& val, int n)
255  {
256  qd_real result = 1.0;
257  qd_real pow2 = val;
258  for (int k = n; k != 0; pow2 *= pow2, k /= 2)
259  if (k % 2)
260  result *= pow2;
261  return result;
262  }
263 
265  template<>
266  inline
267  qd_real
269  pi()
270  { return qd_real::_pi; }
271 
273  template<>
274  inline
275  qd_real
277  ln_2()
278  { return qd_real::_log2; }
279 
281  _GLUCAT_QD_F(qd_real, exp)
282 
283 
284  _GLUCAT_QD_F(qd_real, log)
285 
287  _GLUCAT_QD_F(qd_real, cos)
288 
290  _GLUCAT_QD_F(qd_real, acos)
291 
293  _GLUCAT_QD_F(qd_real, cosh)
294 
296  _GLUCAT_QD_F(qd_real, sin)
297 
299  _GLUCAT_QD_F(qd_real, asin)
300 
302  _GLUCAT_QD_F(qd_real, sinh)
303 
305  _GLUCAT_QD_F(qd_real, tan)
306 
308  _GLUCAT_QD_F(qd_real, atan)
309 
311  _GLUCAT_QD_F(qd_real, tanh)
312 }
313 
314 # endif
315 #endif
316 
317 #endif // _GLUCAT_QD_H
static int to_int(const Scalar_T &val)
Cast to int.
Definition: scalar.h:125
static bool isNaN_or_isInf(const Scalar_T &val)
Smart isnan or isinf.
Definition: scalar.h:102
const Multivector< Scalar_T, LO, HI > sinh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic sine of multivector.
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.
static Scalar_T pi()
Pi.
Definition: scalar.h:188
static bool isInf(const Scalar_T &val, bool_to_type< false >)
Smart isinf specialised for Scalar_T without infinity.
Definition: scalar.h:53
static Scalar_T fmod(const Scalar_T &lhs, const Scalar_T &rhs)
Modulo function for scalar.
Definition: scalar.h:153
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.
const framed_multi< Scalar_T, LO, HI > exp(const framed_multi< Scalar_T, LO, HI > &val)
Exponential of multivector.
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.
const Multivector< Scalar_T, LO, HI > tanh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic tangent of multivector.
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.
static Scalar_T pow(const Scalar_T &val, int n)
Integer power.
Definition: scalar.h:202
static double to_double(const Scalar_T &val)
Cast to double.
Definition: scalar.h:132
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.
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.
static Scalar_T ln_2()
log(2)
Definition: scalar.h:195
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.
const Multivector< Scalar_T, LO, HI > cosh(const Multivector< Scalar_T, LO, HI > &val)
Hyperbolic cosine of multivector.
static bool isNaN(const Scalar_T &val, bool_to_type< false >)
Smart isnan specialised for Scalar_T without quiet NaN.
Definition: scalar.h:67