Rheolef  7.1
an efficient C++ finite element environment
Float.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_FLOAT_H
2 #define _RHEOLEF_FLOAT_H
3 //
4 // This file is part of Rheolef.
5 //
6 // Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7 //
8 // Rheolef is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Rheolef 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 General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Rheolef; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // =========================================================================
23 // compiler-dependent part for rheolef implementation: the floating point
24 // author: Pierre.Saramito@imag.fr
25 // date: 27 january 2000
26 
27 namespace rheolef {
57 } // namespace rheolef
58 
59 #include "rheolef/config.h" /* as generated by configure */
60 
61 #include <cmath>
62 
63 namespace rheolef {
64 using std::cos;
65 using std::sin;
66 using std::tan;
67 using std::acos;
68 using std::asin;
69 using std::atan;
70 using std::cosh;
71 using std::sinh;
72 using std::tanh;
73 using std::exp;
74 using std::log;
75 using std::log10;
76 using std::sqrt;
77 using std::abs;
78 using std::fabs;
79 using std::floor;
80 using std::ceil;
81 using std::atan2;
82 using std::pow;
83 using std::fmod;
84 } // namespace rheolef
85 
86 
87 #include <complex>
88 
89 namespace rheolef {
90 
92 template<class T>
93 struct float_traits {
94  typedef T type;
95 };
96 template<class T>
97 struct float_traits<std::complex<T> >
98 {
99  typedef typename float_traits<T>::type type;
100 };
101 } // namespace rheolef
102 
103 // ==================================================================================================
104 
105 #include <limits>
106 
107 #include "rheolef/numeric_flags.h"
108 
109 // -------------------------------------------------
110 // Float
111 // -------------------------------------------------
112 #if defined(_RHEOLEF_HAVE_FLOAT128)
113 #include <boost/multiprecision/float128.hpp>
114 namespace rheolef {
115 using boost::multiprecision::float128;
116 using namespace boost::multiprecision;
117 static inline float128 sqr (const float128& x) { return (x*x); }
118 static inline float128 norm (const float128& x) { return fabs(x); } // for completeness with field_expr
120 using Float = float128;
121 //using boost::math::isnan;
122 //using boost::math::isinf;
123 //using boost::math::isfinite;
124 //using boost::math::isnormal;
125 } // namespace rheolef
126 
127 #elif defined(_RHEOLEF_HAVE_CLN)
128 # include "rheolef/bigfloat.h"
129 namespace rheolef {
131 typedef bigfloat<_RHEOLEF_DIGITS10> Float;
132 } // namespace rheolef
133 
134 #elif defined(_RHEOLEF_HAVE_LONG_DOUBLE)
135 namespace rheolef {
137 typedef long double Float;
138 } // namespace rheolef
139 
140 #else
141 namespace rheolef {
143 typedef double Float;
144 } // namespace rheolef
145 #endif // Float
146 
147 // is any integer or float type (included extended precision, if used)
148 namespace rheolef { namespace details {
149 template <class T, class Sfinae = void>
150 struct is_rheolef_arithmetic: std::false_type {};
151 
152 template <class T>
154 typename std::enable_if<
155  std::is_arithmetic<T>::value
156  || std::is_same<typename std::decay<T>::type,double>::value
157 >::type>
158 : std::true_type {};
159 
160 #ifdef _RHEOLEF_HAVE_FLOAT128
161 template <class T>
162 struct is_rheolef_arithmetic<T,
163 typename std::enable_if<
164  std::is_same<typename std::decay<T>::type,float128>::value
165 >::type>
166 : std::true_type {};
167 #endif // _RHEOLEF_HAVE_FLOAT128
168 
169 }} // namespace rheolef::details
170 
171 // -------------------------------------------------
172 
173 namespace rheolef { namespace details {
174 template<class T, class Check = T>
176  typedef T type;
177 };
178 template<class Int>
179 struct upgrade_integral_to_float<Int, typename std::enable_if<std::is_integral<Int>::value,Int>::type>
180 {
181  // integers upgrated to default Float
182  typedef Float type;
183 };
184 
185 }} // namespace rheolef::details
186 
187 #if !defined(_RHEOLEF_HAVE_SQR_DOUBLE)
188 namespace rheolef {
189 static inline double sqr (const double& x) { return (x*x); }
190 } // namespace rheolef
191 #endif
192 
193 #include <functional> // greater/less, ect...
194 #include <numeric> // inner_product, ect...
195 #include <algorithm>
196 
197 namespace rheolef {
198 using std::min;
199 using std::max;
200 #ifdef TO_CLEAN
201 // TODO: promote<T1,T2>::type max(T1,T2) {...}
202 // conflict with max(field_nonlinear_expr<E>,int)
203 template <class T> T max (T x, int y) { return x > y ? x : T(y); }
204 template <class T> T max (int x, T y) { return x > y ? T(x) : y; }
205 template <class T> T min (T x, int y) { return x < y ? x : T(y); }
206 template <class T> T min (int x, T y) { return x < y ? T(x) : y; }
207 // conflict with ginac::abs
208 template <class T> T abs (T x) { return (x > T(0) ? x : -x); }
209 #endif // TO_CLEAN
210 } // namespace rheolef
211 
212 #include <climits>
213 
214 #endif // _RHEOLEF_FLOAT_H
rheolef::details::upgrade_integral_to_float::type
T type
Definition: Float.h:176
rheolef::float_traits
helper for std::complex<T>: get basic T type
Definition: Float.h:93
rheolef::pow
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:120
rheolef::details::upgrade_integral_to_float< Int, typename std::enable_if< std::is_integral< Int >::value, Int >::type >::type
Float type
Definition: Float.h:182
rheolef::norm
T norm(const vec< T, M > &x)
norm(x): see the expression page for the full documentation
Definition: vec.h:387
rheolef::type
rheolef::std type
rheolef::exp
tensor_basic< T > exp(const tensor_basic< T > &a, size_t d)
Definition: tensor-exp.cc:92
rheolef::details::upgrade_integral_to_float
Definition: Float.h:175
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::float_traits::type
T type
Definition: Float.h:94
Float
see the Float page for the full documentation
rheolef::float_traits< std::complex< T > >::type
float_traits< T >::type type
Definition: Float.h:99
rheolef::details::is_rheolef_arithmetic
Definition: Float.h:150
rheolef::Float
double Float
see the Float page for the full documentation
Definition: Float.h:143
rheolef::std
Definition: vec_expr_v2.h:391
T
Expr1::float_type T
Definition: field_expr.h:218