glucat
0.13.0
glucat
scalar_imp.h
Go to the documentation of this file.
1
#ifndef _GLUCAT_SCALAR_IMP_H
2
#define _GLUCAT_SCALAR_IMP_H
3
/***************************************************************************
4
GluCat : Generic library of universal Clifford algebra templates
5
scalar_imp.h : Define functions for scalar_t
6
-------------------
7
begin : 2001-12-20
8
copyright : (C) 2001-2014 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
#include "
glucat/qd.h
"
36
37
#include <boost/numeric/ublas/traits.hpp>
38
39
#include <cmath>
40
#include <limits>
41
42
namespace
glucat
43
{
45
// Reference: [AA], 2.4, p. 30-31
46
48
template
< >
49
template
<
typename
Other_Scalar_T >
50
inline
51
auto
52
numeric_traits<float>::
53
to_scalar_t
(
const
Other_Scalar_T& val) ->
float
54
{
return
static_cast<
float
>
(
numeric_traits<Other_Scalar_T>::to_double
(val)); }
55
57
template
< >
58
template
<
typename
Other_Scalar_T >
59
inline
60
auto
61
numeric_traits<double>::
62
to_scalar_t
(
const
Other_Scalar_T& val) ->
double
63
{
return
numeric_traits<Other_Scalar_T>::to_double
(val); }
64
65
#if defined(_GLUCAT_USE_QD)
67
template
< >
68
template
< >
69
inline
70
auto
71
numeric_traits<long double>::
72
to_scalar_t
(
const
dd_real& val) ->
long
double
73
{
return
static_cast<
long
double
>
(val.x[0]) +
static_cast<
long
double
>
(val.x[1]); }
74
76
template
< >
77
template
< >
78
inline
79
auto
80
numeric_traits<long double>::
81
to_scalar_t
(
const
qd_real& val) ->
long
double
82
{
return
static_cast<
long
double
>
(val.x[0]) +
static_cast<
long
double
>
(val.x[1]); }
83
85
template
< >
86
template
< >
87
inline
88
auto
89
numeric_traits<dd_real>::
90
to_scalar_t
(
const
long
double
& val) -> dd_real
91
{
return
{double(val),double(val -
static_cast<
long
double
>
(
double
(val)))}; }
92
94
template
< >
95
template
< >
96
inline
97
auto
98
numeric_traits<dd_real>::
99
to_scalar_t
(
const
qd_real& val) -> dd_real
100
{
return
{val.x[0],val.x[1]}; }
101
103
template
< >
104
template
< >
105
inline
106
auto
107
numeric_traits<qd_real>::
108
to_scalar_t
(
const
long
double
& val) -> qd_real
109
{
return
{double(val),double(val -
static_cast<
long
double
>
(
double
(val))),0.0,0.0}; }
110
112
template
< >
113
template
< >
114
inline
115
auto
116
numeric_traits<qd_real>::
117
to_scalar_t
(
const
dd_real& val) -> qd_real
118
{
return
{val.x[0],val.x[1],0.0,0.0}; }
119
#endif
120
122
template
<
typename
Scalar_T >
123
inline
124
auto
125
to_promote
(
const
Scalar_T& val) ->
typename
numeric_traits<Scalar_T>::promoted::type
126
{
127
using
promoted_scalar_t =
typename
numeric_traits<Scalar_T>::promoted::type
;
128
return
numeric_traits<promoted_scalar_t>::to_scalar_t
(val);
129
}
130
132
template
<
typename
Scalar_T >
133
inline
134
auto
135
to_demote
(
const
Scalar_T& val) ->
typename
numeric_traits<Scalar_T>::demoted::type
136
{
137
using
demoted_scalar_t =
typename
numeric_traits<Scalar_T>::demoted::type
;
138
return
numeric_traits<demoted_scalar_t>::to_scalar_t
(val);
139
}
140
}
141
142
#endif
// _GLUCAT_SCALAR_IMP_H
glucat::numeric_traits::to_scalar_t
static auto to_scalar_t(const Other_Scalar_T &val) -> Scalar_T
Cast to Scalar_T.
Definition
scalar.h:141
glucat::numeric_traits::to_double
static auto to_double(const Scalar_T &val) -> double
Cast to double.
Definition
scalar.h:133
glucat
Definition
clifford_algebra.h:42
glucat::to_demote
auto to_demote(const Scalar_T &val) -> typename numeric_traits< Scalar_T >::demoted::type
Cast to demote.
Definition
scalar_imp.h:135
glucat::to_promote
auto to_promote(const Scalar_T &val) -> typename numeric_traits< Scalar_T >::promoted::type
Cast to promote.
Definition
scalar_imp.h:125
qd.h
scalar.h
glucat::numeric_traits::demoted::type
float type
Definition
promotion.h:78
glucat::numeric_traits::promoted::type
double type
Definition
promotion.h:72
Generated by
1.13.2