OpcUaCanOpen
CANopen OPC-UA server
muParserTemplateMagic.h
Go to the documentation of this file.
1 #ifndef MU_PARSER_TEMPLATE_MAGIC_H
2 #define MU_PARSER_TEMPLATE_MAGIC_H
3 
4 #include <cmath>
5 #include "muParserError.h"
6 
7 
8 namespace mu
9 {
10  //-----------------------------------------------------------------------------------------------
11  //
12  // Compile time type detection
13  //
14  //-----------------------------------------------------------------------------------------------
15 
19  template<typename T>
20  struct TypeInfo
21  {
22  static bool IsInteger() { return false; }
23  };
24 
25  template<>
26  struct TypeInfo<char>
27  {
28  static bool IsInteger() { return true; }
29  };
30 
31  template<>
32  struct TypeInfo<short>
33  {
34  static bool IsInteger() { return true; }
35  };
36 
37  template<>
38  struct TypeInfo<int>
39  {
40  static bool IsInteger() { return true; }
41  };
42 
43  template<>
44  struct TypeInfo<long>
45  {
46  static bool IsInteger() { return true; }
47  };
48 
49  template<>
50  struct TypeInfo<unsigned char>
51  {
52  static bool IsInteger() { return true; }
53  };
54 
55  template<>
56  struct TypeInfo<unsigned short>
57  {
58  static bool IsInteger() { return true; }
59  };
60 
61  template<>
62  struct TypeInfo<unsigned int>
63  {
64  static bool IsInteger() { return true; }
65  };
66 
67  template<>
68  struct TypeInfo<unsigned long>
69  {
70  static bool IsInteger() { return true; }
71  };
72 
73 
74  //-----------------------------------------------------------------------------------------------
75  //
76  // Standard math functions with dummy overload for integer types
77  //
78  //-----------------------------------------------------------------------------------------------
79 
85  template<typename T>
86  struct MathImpl
87  {
88  static T Sin(T v) { return sin(v); }
89  static T Cos(T v) { return cos(v); }
90  static T Tan(T v) { return tan(v); }
91  static T ASin(T v) { return asin(v); }
92  static T ACos(T v) { return acos(v); }
93  static T ATan(T v) { return atan(v); }
94  static T ATan2(T v1, T v2) { return atan2(v1, v2); }
95  static T Sinh(T v) { return sinh(v); }
96  static T Cosh(T v) { return cosh(v); }
97  static T Tanh(T v) { return tanh(v); }
98  static T ASinh(T v) { return log(v + sqrt(v * v + 1)); }
99  static T ACosh(T v) { return log(v + sqrt(v * v - 1)); }
100  static T ATanh(T v) { return ((T)0.5 * log((1 + v) / (1 - v))); }
101  static T Log(T v) { return log(v); }
102  static T Log2(T v) { return log(v)/log((T)2); } // Logarithm base 2
103  static T Log10(T v) { return log10(v); } // Logarithm base 10
104  static T Exp(T v) { return exp(v); }
105  static T Abs(T v) { return (v>=0) ? v : -v; }
106  static T Sqrt(T v) { return sqrt(v); }
107  static T Rint(T v) { return floor(v + (T)0.5); }
108  static T Sign(T v) { return (T)((v<0) ? -1 : (v>0) ? 1 : 0); }
109  static T Pow(T v1, T v2) { return std::pow(v1, v2); }
110  };
111 }
112 
113 #endif