15#define TYPE_TAG_(UNIVERSAL_TYPE) UNIVERSAL_TYPE ## _type_tag
16#define TYPE_TAG(UNIVERSAL_TYPE) TYPE_TAG_(UNIVERSAL_TYPE)
17#define UNIVERSAL_TYPE_TAG TYPE_TAG(UNIVERSAL_TYPE)
27struct UNIVERSAL_TYPE_TAG {};
29template<>
struct number_type<UNIVERSAL_TYPE> {
typedef UNIVERSAL_TYPE_TAG type; };
32struct epsilon_type<UNIVERSAL_TYPE>
34 static inline UNIVERSAL_TYPE value()
36 static const UNIVERSAL_TYPE epsilon =
37 std::numeric_limits<UNIVERSAL_TYPE>::epsilon();
42inline bool is_nan_impl(
const UNIVERSAL_TYPE& v, UNIVERSAL_TYPE_TAG)
48inline int to_int32_impl(
const T& v, UNIVERSAL_TYPE_TAG)
50 return static_cast<int>(v);
55inline long long to_int64_impl(
const T& v, UNIVERSAL_TYPE_TAG)
57 return static_cast<long long int>(v);
62inline unsigned long long to_uint64_impl(
const T& v, UNIVERSAL_TYPE_TAG)
64 return static_cast<unsigned long long int>(v);
67template <
typename T>
inline T abs_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::abs (v); }
68template <
typename T>
inline T acos_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::acos (v); }
69template <
typename T>
inline T acosh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::acosh(v); }
70template <
typename T>
inline T asin_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::asin (v); }
71template <
typename T>
inline T asinh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::asinh(v); }
72template <
typename T>
inline T atan_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::atan (v); }
73template <
typename T>
inline T atanh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::atanh(v); }
74template <
typename T>
inline T ceil_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::ceil (v); }
75template <
typename T>
inline T cos_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::cos (v); }
76template <
typename T>
inline T cosh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::cosh (v); }
77template <
typename T>
inline T exp_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::exp (v); }
78template <
typename T>
inline T floor_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::floor(v); }
79template <
typename T>
inline T log_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::log (v); }
80template <
typename T>
inline T log10_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::log10(v); }
81template <
typename T>
inline T log2_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::log2 (v); }
82template <
typename T>
inline T neg_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return -v; }
83template <
typename T>
inline T pos_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return v; }
84template <
typename T>
inline T sin_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::sin (v); }
85template <
typename T>
inline T sinh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::sinh (v); }
86template <
typename T>
inline T sqrt_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::sqrt (v); }
87template <
typename T>
inline T tan_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::tan (v); }
88template <
typename T>
inline T tanh_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::tanh (v); }
89template <
typename T>
inline T cot_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::cot (v); }
90template <
typename T>
inline T sec_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::sec (v); }
91template <
typename T>
inline T csc_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::csc (v); }
92template <
typename T>
inline T r2d_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return (v * exprtk::details::constant_universal::_180_pi); }
93template <
typename T>
inline T d2r_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return (v * exprtk::details::constant_universal::pi_180 ); }
94template <
typename T>
inline T d2g_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return (v * UNIVERSAL_TYPE(10.0/9.0)); }
95template <
typename T>
inline T g2d_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return (v * UNIVERSAL_TYPE(9.0/10.0)); }
96template <
typename T>
inline T notl_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return (v != UNIVERSAL_TYPE(0) ? UNIVERSAL_TYPE(0) : UNIVERSAL_TYPE(1)); }
97template <
typename T>
inline T frac_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::frac (v); }
98template <
typename T>
inline T trunc_impl(
const T& v, UNIVERSAL_TYPE_TAG) {
return sw::universal::trunc(v); }
100template <
typename T>
inline T const_pi_impl(UNIVERSAL_TYPE_TAG) {
return UNIVERSAL_TYPE(exprtk::details::constant_universal::pi); }
101template <
typename T>
inline T const_e_impl (UNIVERSAL_TYPE_TAG) {
return UNIVERSAL_TYPE(exprtk::details::constant_universal::e ); }
103inline bool is_true_impl (
const UNIVERSAL_TYPE& v)
109inline bool is_false_impl(
const UNIVERSAL_TYPE& v)
111 return !is_true_impl(v);
115inline T expm1_impl(
const T& v, UNIVERSAL_TYPE_TAG)
117 return sw::universal::expm1(v);
121inline T min_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
123 return sw::universal::min(v0,v1);
127inline T max_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
129 return sw::universal::max(v0,v1);
133inline T nequal_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
135 const T epsilon = epsilon_type<T>::value();
136 const T eps_norm = (sw::universal::max(T(1),sw::universal::max(sw::universal::abs(v0),sw::universal::abs(v1))) * epsilon);
137 return (sw::universal::abs(T(v0 - v1)) > eps_norm) ? T(1) : T(0);
141inline T sgn_impl(
const T& v, UNIVERSAL_TYPE_TAG)
143 if (v > T(0))
return T(+1);
144 else if (v < T(0))
return T(-1);
149inline T log1p_impl(
const T& v, UNIVERSAL_TYPE_TAG)
151 return sw::universal::log1p(v);
155inline T erf_impl(
const T& v, UNIVERSAL_TYPE_TAG)
157 return sw::universal::erf(v);
161inline T erfc_impl(
const T& v, UNIVERSAL_TYPE_TAG)
163 return sw::universal::erfc(v);
167inline T ncdf_impl(
const T& v, UNIVERSAL_TYPE_TAG)
169 T cnd = T(0.5) * (T(1) + erf_impl(
170 sw::universal::abs(v) /
171 T(exprtk::details::constant_universal::sqrt2), UNIVERSAL_TYPE_TAG()));
172 return (v < T(0)) ? (T(1) - cnd) : cnd;
176inline T modulus_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
178 std::cerr<<
"modulus is not derivated\n";
179 return T(sw::universal::fmod(v0,v1));
184inline T pow_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
186 return sw::universal::pow(v0, v1 );
191inline T logn_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
193 return sw::universal::log(v0) / sw::universal::log(v1);
197inline T sinc_impl(
const T& v, UNIVERSAL_TYPE_TAG)
199 if (sw::universal::abs(v) >= epsilon_type<T>::value())
200 return(sw::universal::sin(v) / v);
206inline T xor_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
208 return (is_false_impl(v0) != is_false_impl(v1)) ? T(1) : T(0);
212inline T xnor_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
214 const bool v0_true = is_true_impl(v0);
215 const bool v1_true = is_true_impl(v1);
216 if ((v0_true && v1_true) || (!v0_true && !v1_true))
223inline T equal_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
225 const T epsilon = epsilon_type<T>::value();
226 const T eps_norm = (sw::universal::max(T(1),sw::universal::max(sw::universal::abs(v0),sw::universal::abs(v1))) * epsilon);
227 return (sw::universal::abs(T(v0-v1)) <= eps_norm) ? T(1) : T(0);
231inline T round_impl(
const T& v, UNIVERSAL_TYPE_TAG)
233 return sw::universal::round(v);
237inline T roundn_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
239 const T p10 = pow(T(10),floor(v1));
241 return T(sw::universal::ceil (T((v0 * p10) - T(0.5))) / p10);
243 return T(sw::universal::floor(T((v0 * p10) + T(0.5))) / p10);
247inline bool is_integer_impl(
const T& v, UNIVERSAL_TYPE_TAG)
249 return sw::universal::ceil(v) == v;
254inline T root_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
256 return sw::universal::pow(v0,T(1) / v1);
260inline T hypot_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
262 return sw::universal::hypot(v0,v1);
266inline T atan2_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
268 return sw::universal::atan2(v0,v1);
272inline T shr_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
274 return v0 * (T(1) / sw::universal::pow(T(2.0),v1));
278inline T shl_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
280 return v0 * sw::universal::pow(T(2.0),v1);
284inline T and_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
286 return (is_true_impl(v0) && is_true_impl(v1)) ? T(1) : T(0);
290inline T nand_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
292 return (is_false_impl(v0) || is_false_impl(v1)) ? T(1) : T(0);
296inline T or_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
298 return (is_true_impl(v0) || is_true_impl(v1)) ? T(1) : T(0);
302inline T nor_impl(
const T& v0,
const T& v1, UNIVERSAL_TYPE_TAG)
304 return (is_false_impl(v0) && is_false_impl(v1)) ? T(1) : T(0);
309template <
typename Iterator>
310inline bool string_to_real(Iterator& itr_external,
311 const Iterator end, UNIVERSAL_TYPE& t,
312 numeric::details::UNIVERSAL_TYPE_TAG)
314 const std::string num(itr_external,end);
315 t = ::atof(num.c_str());
319inline bool is_true (
const UNIVERSAL_TYPE& v)
320{
return details::numeric::details::is_true_impl (v); }
322inline bool is_false(
const UNIVERSAL_TYPE& v)
323{
return details::numeric::details::is_false_impl(v); }
330inline void print_type(
const std::string&,
const UNIVERSAL_TYPE& v,
331 exprtk::details::numeric::details::UNIVERSAL_TYPE_TAG)
333 std::cout << pretty_print(v) <<
"\n";