15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_DETAIL_STD_SATURATEDCASTREG_H__ 16 #define __IPSDKUTIL_INSTRUCTIONSET_DETAIL_STD_SATURATEDCASTREG_H__ 24 #include <boost/type_traits/is_same.hpp> 25 #include <boost/type_traits/is_signed.hpp> 34 template <
typename TIn,
typename TOut>
36 typename boost::enable_if_c<
37 boost::is_same<TIn, TOut>::value
41 static IPSDK_FORCEINLINE
45 TOut out =
static_cast<TOut
>(in);
46 return static_cast<TOut
>(in);
49 static IPSDK_FORCEINLINE
51 act(
const TIn& in, TOut& out)
53 out =
static_cast<TOut
>(in);
57 template <
typename TIn,
typename TOut>
59 typename boost::enable_if_c<
60 boost::is_integral<TIn>::value &&
61 boost::is_integral<TOut>::value &&
62 boost::is_signed<TIn>::value==boost::is_signed<TOut>::value &&
63 sizeof(TIn)<sizeof(TOut)
67 static IPSDK_FORCEINLINE
71 return static_cast<TOut
>(in);
74 static IPSDK_FORCEINLINE
76 act(
const TIn& in, TOut& out)
78 out =
static_cast<TOut
>(in);
82 template <
typename TIn,
typename TOut>
84 typename boost::enable_if_c<
85 boost::is_integral<TIn>::value &&
86 boost::is_integral<TOut>::value &&
87 boost::is_signed<TIn>::value &&
88 !boost::is_signed<TOut>::value &&
89 sizeof(TOut)>=sizeof(TIn)
93 static IPSDK_FORCEINLINE
97 const TIn clampedIn = in >= 0 ? in : 0;
98 return static_cast<TOut
>(clampedIn);
101 static IPSDK_FORCEINLINE
103 act(
const TIn& in, TOut& out)
105 const TIn clampedIn = in >= 0 ? in : 0;
106 out =
static_cast<TOut
>(clampedIn);
110 template <
typename TIn,
typename TOut>
112 typename boost::enable_if_c<
113 boost::is_integral<TIn>::value &&
114 boost::is_integral<TOut>::value &&
115 !boost::is_signed<TIn>::value &&
116 boost::is_signed<TOut>::value &&
117 sizeof(TOut)<=sizeof(TIn)
121 static IPSDK_FORCEINLINE
125 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
126 const TIn clampedIn = (in >= nMax ? nMax : in);
127 return static_cast<TOut
>(clampedIn);
130 static IPSDK_FORCEINLINE
132 act(
const TIn& in, TOut& out)
134 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
135 const TIn clampedIn = (in >= nMax ? nMax : in);
136 out =
static_cast<TOut
>(clampedIn);
140 template <
typename TIn,
typename TOut>
142 typename boost::enable_if_c<
143 boost::is_integral<TIn>::value &&
144 boost::is_integral<TOut>::value &&
145 !boost::is_signed<TIn>::value &&
146 boost::is_signed<TOut>::value &&
147 (sizeof(TOut) > sizeof(TIn))
151 static IPSDK_FORCEINLINE
155 return static_cast<TOut
>(in);
158 static IPSDK_FORCEINLINE
160 act(
const TIn& in, TOut& out)
162 out =
static_cast<TOut
>(in);
166 template <
typename TIn,
typename TOut>
168 typename boost::enable_if_c<
169 boost::is_integral<TIn>::value &&
170 boost::is_integral<TOut>::value &&
171 !boost::is_signed<TIn>::value &&
172 !boost::is_signed<TOut>::value &&
173 sizeof(TOut)<sizeof(TIn)
177 static IPSDK_FORCEINLINE
181 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
182 const TIn clampedIn = (in >= nMax ? nMax : in);
183 return static_cast<TOut
>(clampedIn);
186 static IPSDK_FORCEINLINE
188 act(
const TIn& in, TOut& out)
190 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
191 const TIn clampedIn = (in >= nMax ? nMax : in);
192 out =
static_cast<TOut
>(clampedIn);
196 template <
typename TIn,
typename TOut>
198 typename boost::enable_if_c<
199 boost::is_integral<TIn>::value &&
200 boost::is_integral<TOut>::value &&
201 boost::is_signed<TIn>::value &&
202 sizeof(TOut)<sizeof(TIn)
206 static IPSDK_FORCEINLINE
210 const TIn nMin =
static_cast<TIn
>(NumericLimits<TOut>::min());
211 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
212 TIn clampedIn = (in > nMax ? nMax : in);
213 clampedIn = (clampedIn < nMin ? nMin : clampedIn);
214 return static_cast<TOut
>(clampedIn);
217 static IPSDK_FORCEINLINE
219 act(
const TIn& in, TOut& out)
221 const TIn nMin =
static_cast<TIn
>(NumericLimits<TOut>::min());
222 const TIn nMax =
static_cast<TIn
>(NumericLimits<TOut>::max());
223 TIn clampedIn = (in > nMax ? nMax : in);
224 clampedIn = (clampedIn < nMin ? nMin : clampedIn);
225 out =
static_cast<TOut
>(clampedIn);
229 template <
typename TIn>
231 typename boost::enable_if_c<boost::is_integral<TIn>::value>::type>
233 static IPSDK_FORCEINLINE
241 static IPSDK_FORCEINLINE
249 template <
typename TOut>
251 typename boost::enable_if_c<boost::is_integral<TOut>::value>::type>
253 static IPSDK_FORCEINLINE
260 clampedIn = (clampedIn > fMax ? fMax : clampedIn);
261 clampedIn = (clampedIn < fMin ? fMin : clampedIn);
262 return static_cast<TOut
>(clampedIn);
265 static IPSDK_FORCEINLINE
272 clampedIn = (clampedIn > fMax ? fMax : clampedIn);
273 clampedIn = (clampedIn < fMin ? fMin : clampedIn);
274 out =
static_cast<TOut
>(clampedIn);
278 template <
typename TIn>
280 typename boost::enable_if_c<
281 !boost::is_same<TIn, ipReal64>::value
285 static IPSDK_FORCEINLINE
292 static IPSDK_FORCEINLINE
300 template <
typename TOut>
302 typename boost::enable_if_c<
303 !boost::is_same<ipReal64, TOut>::value
307 static IPSDK_FORCEINLINE
313 ipReal64 clampedIn = (in > fMax ? fMax : in);
314 clampedIn = (clampedIn < fMin ? fMin : clampedIn);
315 return static_cast<TOut
>(clampedIn);
318 static IPSDK_FORCEINLINE
324 ipReal64 clampedIn = (in > fMax ? fMax : in);
325 clampedIn = (clampedIn < fMin ? fMin : clampedIn);
326 out =
static_cast<TOut
>(clampedIn);
337 #endif // __IPSDKUTIL_INSTRUCTIONSET_DETAIL_STD_SATURATEDCASTREG_H__ Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: SaturatedCastReg.h:33
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
eInstructionSet
Enumerate for processor instruction set description.
Definition: InstructionSetTypes.h:31
Definition of import/export macro for library.
compiler optimisations only
Definition: InstructionSetTypes.h:34
float ipReal32
Base types definition.
Definition: BaseTypes.h:56