Debian Codegraph @

src/acl/DataTypes/aclConstant.cxx

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #include "aclConstant.h"
25 #include "../aclUtilities.h"
26
27 #include <math.h>
28 #include "aclTypesList.h"
29
30
31 namespace acl
32 {
33
34 template <typename T> Constant<T>::Constant(T c):
35 ElementBase(false, 0, typeToTypeID<T>()),
36 value(c)
37 {
38 stringstream s;
39 if( value < 0 )
40 s << "(" << value << ")";
41 else
42 s << value;
43 valueStr = s.str();
44 }
45
46 template <> Constant<cl_double>::Constant(cl_double c):
47 ElementBase(false, 0, typeToTypeID<cl_double>()),
48 value(c)
49 {
50 stringstream s;
51 double intp(0.);
52 if (modf(value, &intp) == 0. && std::fabs(value) < 10000)
53 s << value << ".";
54 else
55 {
56 s.precision(20);
57 s << value;
58 }
59 valueStr = s.str();
60 }
61
62 template <> Constant<cl_float>::Constant(cl_float c):
63 ElementBase(false, 0, typeToTypeID<cl_float>()),
64 value(c)
65 {
66 stringstream s;
67 float intp(0.);
68 if (modf(value, &intp) == 0. && std::fabs(value) < 10000)
69 s << value << ".";
70 else
71 {
72 s.precision(10);
73 s << value;
74 }
75 valueStr = s.str();
76 }
77
78 #define BOOST_TT_rep_expression(r,data,t) \
79 template Constant<t>::Constant(t c);
80 BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types)
81 #undef BOOST_TT_rep_expression
82
83 } // namespace acl