74 template <
class T1,
class T2>
106 #define SPECIALIZE_PROMOTE_TRAIT(T_TYPE, T_PARAMS, T_ARGS) \
107 template <T_PARAMS> class T_TYPE; \
108 template <> struct promote_trait<T_TYPE<byte T_ARGS> , byte> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
109 template <> struct promote_trait<T_TYPE<byte T_ARGS> , int16> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
110 template <> struct promote_trait<T_TYPE<byte T_ARGS> , int32> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
111 template <> struct promote_trait<T_TYPE<byte T_ARGS> , float> { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
112 template <> struct promote_trait<T_TYPE<byte T_ARGS> , double> { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
113 template <> struct promote_trait<T_TYPE<byte T_ARGS> , long double> { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
115 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , byte> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
116 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , int16> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
117 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , int32> { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
118 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , float> { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
119 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , double> { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
120 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , long double> { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
122 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , float> { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
123 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , double> { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
124 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , long double> { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
126 template <> struct promote_trait<T_TYPE<float T_ARGS> , double> { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
127 template <> struct promote_trait<T_TYPE<float T_ARGS> , long double> { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
129 template <> struct promote_trait<T_TYPE<double T_ARGS> , long double> { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
131 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<byte T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
132 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<int16 T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
133 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<int32 T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
134 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<float T_ARGS> > { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
135 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<double T_ARGS> > { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
136 template <> struct promote_trait<T_TYPE<byte T_ARGS> , T_TYPE<long double T_ARGS> > { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
138 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<byte T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
139 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<int16 T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
140 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<int32 T_ARGS> > { typedef T_TYPE<int T_ARGS> TP; enum { willPromote = 1 }; }; \
141 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<float T_ARGS> > { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
142 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<double T_ARGS> > { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
143 template <> struct promote_trait<T_TYPE<int16 T_ARGS> , T_TYPE<long double T_ARGS> > { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
145 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , T_TYPE<float T_ARGS> > { typedef T_TYPE<float T_ARGS> TP; enum { willPromote = 1 }; }; \
146 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , T_TYPE<double T_ARGS> > { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
147 template <> struct promote_trait<T_TYPE<int32 T_ARGS> , T_TYPE<long double T_ARGS> > { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
149 template <> struct promote_trait<T_TYPE<float T_ARGS> , T_TYPE<double T_ARGS> > { typedef T_TYPE<double T_ARGS> TP; enum { willPromote = 1 }; }; \
150 template <> struct promote_trait<T_TYPE<float T_ARGS> , T_TYPE<long double T_ARGS> > { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; }; \
152 template <> struct promote_trait<T_TYPE<double T_ARGS> , T_TYPE<long double T_ARGS> > { typedef T_TYPE<long double T_ARGS> TP; enum { willPromote = 1 }; };
178 template <
class T1,
class T2>
216 template <
class dst_type,
class src_type,
218 (std::numeric_limits<dst_type>::is_integer
219 && !std::numeric_limits<src_type>::is_integer)>
222 template <
class dst_type,
class src_type>
225 inline static dst_type
round(src_type x)
226 {
return dst_type(x); }
229 template <
class dst_type,
class src_type>
232 inline static dst_type
round(src_type x)
234 if (x > 0)
return dst_type(x+0.5);
235 else if (x < 0)
return dst_type(x-0.5);
236 else return dst_type(0);
244 template <
class dst_type,
class src_type,
246 bool dst_type_is_integer = std::numeric_limits<dst_type>::is_integer>
250 template <
class dst_type,
class src_type>
257 if (x < std::numeric_limits<dst_type>::min())
return std::numeric_limits<dst_type>::min();
258 if (x > std::numeric_limits<dst_type>::max())
return std::numeric_limits<dst_type>::max();
264 if (x < std::numeric_limits<dst_type>::min())
return std::numeric_limits<dst_type>::min();
265 if (x > std::numeric_limits<dst_type>::max())
return std::numeric_limits<dst_type>::max();
272 template <
class dst_type,
class src_type>
279 if (x < -std::numeric_limits<dst_type>::max())
return -std::numeric_limits<dst_type>::max();
280 if (x > std::numeric_limits<dst_type>::max())
return std::numeric_limits<dst_type>::max();
286 if (x < -std::numeric_limits<dst_type>::max())
return -std::numeric_limits<dst_type>::max();
287 if (x > std::numeric_limits<dst_type>::max())
return std::numeric_limits<dst_type>::max();
298 template <
class dst_type,
class src_type>
314 template <
class dst_type,
class src_type>
331 template <
class dst_type,
class src_type>
339 template <
class dst_type,
class src_type>