ML Reference
mlUtilsSystem.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_UTILS_SYSTEM_H
14 #define ML_UTILS_SYSTEM_H
15 
17 
18 #include <type_traits>
19 
20 //------------------------------------------------------------------------------------
27 //------------------------------------------------------------------------------------
28 #ifndef MEVIS_TARGET
30 #if !defined(MEVIS_TARGET)
31 # error "The compiler definition MEVIS_TARGET is not set! It must specify the name of the compiled executable (without _d etc.)"
32 #endif
33 #endif
34 
35 
36 //------------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------------
41 #ifndef ML_UTILS_NAMESPACE
42 #define ML_UTILS_NAMESPACE ml
43 #endif
44 
48 #ifndef ML_UTILS_START_NAMESPACE
49 #define ML_UTILS_START_NAMESPACE namespace ML_UTILS_NAMESPACE {
50 #endif
51 
53 #ifndef ML_UTILS_END_NAMESPACE
54 #define ML_UTILS_END_NAMESPACE }
55 #endif
57 
58 #include "mlTypeDefs.h"
59 
60 ML_UTILS_START_NAMESPACE
61 
62 //------------------------------------------------------------------------------------
63 //
66 //
67 //------------------------------------------------------------------------------------
68 
71 template<typename T> T mlMin(T a, T b){ return a < b ? a : b; }
72 
75 template<typename T> T mlMax(T a, T b){ return a > b ? a : b; }
76 
77 #if defined(__GNUC__)
78  #pragma GCC diagnostic push
79  // unary minus converts char and short to int - do not print a warning
80  #pragma GCC diagnostic ignored "-Wsign-conversion"
81 #endif
82 
84 template<typename T> T mlAbs(T a){ if constexpr (std::is_signed<T>::value) return a < 0 ? -a : a; else return a; }
86 
87 #if defined(__GNUC__)
88  #pragma GCC diagnostic pop
89 #endif
90 
91 ML_UTILS_END_NAMESPACE
92 
93 // The following block is currently for VC7 only, but might be necessary for VC8 too!
94 #ifdef WIN32
95  #if _MSC_VER >= 1300
96 //------------------------------------------------------------------------------------
97 //
99 // e.g., fabs(static_cast<int>(10)) could have been fabs(float),
100 // fabs(double), or fabs(long double).
102 //
103 //------------------------------------------------------------------------------------
104 
105 // We include \c cmath, so that always the standard functions are defined if these
106 // overloads are defined.
107 #include <ThirdPartyWarningsDisable.h>
108 #include <cmath>
109 #include <ThirdPartyWarningsRestore.h>
110 
111 inline long double pow( __int64 i, int value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
112 inline long double pow(unsigned __int64 i, int value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
113 inline long double pow( __int64 i, float value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
114 inline long double pow(unsigned __int64 i, float value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
115 inline long double pow( __int64 i, double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
116 inline long double pow(unsigned __int64 i, double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
117 inline long double pow( __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
118 inline long double pow(unsigned __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
119 
120 inline unsigned __int64 abs (unsigned __int64 i) { return i; }
121 inline long double fabs( __int64 i) { return static_cast<long double>(i < 0 ? -i : i); }
122 inline long double fabs(unsigned __int64 i) { return static_cast<long double>(i); }
123 
124 #if _MSC_VER >= 1600
125 inline double pow (float f, double d ) { return pow(static_cast<double>(f), d); }
126 #endif // _MSC_VER >= 1600
127 inline double pow (double d, float f ) { return pow(d, static_cast<double>(f)); }
128 inline double pow (double d, unsigned int i ) { return pow(d, static_cast<double>(i)); }
129 inline long double pow (double d, __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
130 inline long double pow (double d, unsigned __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
131 inline long double pow (double d, long double ld) { return pow(static_cast<long double>(d), ld); }
132 inline long double pow (long double ld, double d ) { return pow(ld, static_cast<long double>(d)); }
133 
134 template <typename T> inline double atan (T value) { return atan (static_cast<double>(value)); }
135 template <typename T> inline double ceil (T value) { return ceil (static_cast<double>(value)); }
136 template <typename T> inline double exp (T value) { return exp (static_cast<double>(value)); }
137 template <typename T> inline double fabs (T value) { return fabs (static_cast<double>(value)); }
138 template <typename T> inline double floor(T value) { return floor(static_cast<double>(value)); }
139 template <typename T> inline double log (T value) { return log (static_cast<double>(value)); }
140 template <typename T> inline double sqrt (T value) { return sqrt (static_cast<double>(value)); }
141 template <typename T> inline double pow (int i, T value) { return pow (static_cast<double>(i), value); }
142 template <typename T> inline double pow (unsigned int i, T value) { return pow (static_cast<double>(i), value); }
143 template <typename T> inline long double pow ( __int64 i, T value) { return pow (static_cast<long double>(i), static_cast<long double>(value)); }
144 template <typename T> inline long double pow (unsigned __int64 i, T value) { return pow (static_cast<long double>(i), static_cast<long double>(value)); }
145 #if _MSC_VER < 1600
146 template <typename T> inline double pow (float f, T value) { return pow (static_cast<double>(f), value); }
147 #endif // _MSC_VER < 1600
149 
150  #endif
151 #endif // WIN32 && _MSCVER >= 1300 && _MSC_VER < 1400
152 
153 //------------------------------------------------------------------------------------
154 //
158 //
159 //------------------------------------------------------------------------------------
160 
161 #define ML_TYPENAME typename
163 
164 
165 #endif // __mlUtilsSystem_H
166 
167 
T mlAbs(T a)
Defines ML specific abs template since only type-dependent library functions exists.
Definition: mlUtilsSystem.h:84
T mlMax(T a, T b)
Defines ML specific max template since max template is platform-dependent.
Definition: mlUtilsSystem.h:75
DT abs(DT val)
T mlMin(T a, T b)
Defines ML specific min template since min template is platform-dependent.
Definition: mlUtilsSystem.h:71