40 inline T
clip(T tX, T tMin, T tMax){
41 return tX < tMin ? tMin : tX > tMax ? tMax : tX;
51 template<>
inline bool is_float_type<float>() {
return true; }
52 template<>
inline bool is_float_type<double>() {
return true; }
55 template<
class S,
class D>
58 if(is_float_type<D>()){
59 return src < -(std::numeric_limits<D>::max)() ? -(std::numeric_limits<D>::max)() :
60 src > (std::numeric_limits<D>::max)() ? (std::numeric_limits<D>::max)() :
63 return src < (std::numeric_limits<D>::min)() ? (std::numeric_limits<D>::min)() :
64 src > (std::numeric_limits<D>::max)() ? (std::numeric_limits<D>::max)() :
70 #define SPECIALISE_CLIPPED_CAST(T) template<> inline T clipped_cast<T,T>(T t) { return t; } 72 SPECIALISE_CLIPPED_CAST(
int)
73 SPECIALISE_CLIPPED_CAST(
unsigned int)
74 SPECIALISE_CLIPPED_CAST(
char)
75 SPECIALISE_CLIPPED_CAST(
unsigned char)
76 SPECIALISE_CLIPPED_CAST(
short)
77 SPECIALISE_CLIPPED_CAST(
unsigned short)
78 SPECIALISE_CLIPPED_CAST(
long)
79 SPECIALISE_CLIPPED_CAST(
unsigned long)
80 SPECIALISE_CLIPPED_CAST(
bool)
81 SPECIALISE_CLIPPED_CAST(
float)
82 SPECIALISE_CLIPPED_CAST(
double)
83 #undef SPECIALISE_CLIPPED_CAST undocument this line if you encounter any issues!
Definition: Any.h:37
D clipped_cast(S src)
utility cast function wrapping the standard lib's numerical_limits template
Definition: ClippedCast.h:57
bool is_float_type()
Definition: ClippedCast.h:46
T clip(T tX, T tMin, T tMax)
clips a value into the range [tMin,tMax]
Definition: ClippedCast.h:40