Use lowest instead of min in casting checks
This commit is contained in:
parent
71c0f02873
commit
9124791a59
@ -78,9 +78,23 @@ namespace detail {
|
|||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
T
|
T
|
||||||
_trunc_cast (const typename std::enable_if<sizeof (T) < sizeof (V) &&
|
_trunc_cast (const typename std::enable_if<sizeof (T) < sizeof (V) &&
|
||||||
std::is_signed<T>::value == std::is_signed<V>::value, V>::type v) {
|
std::is_signed<T>::value == std::is_signed<V>::value &&
|
||||||
CHECK_HARD (v <= std::numeric_limits<T>::max ());
|
std::is_integral<T>::value, V>::type v) {
|
||||||
checK_hard (v >= std::numeric_limits<T>::min ());
|
CHECK_HARD (v <= std::numeric_limits<T>::max ());
|
||||||
|
CHECK_HARD (v >= std::numeric_limits<T>::lowest ());
|
||||||
|
|
||||||
|
return static_cast<T> (v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, typename V>
|
||||||
|
T
|
||||||
|
_trunc_cast (const typename std::enable_if<sizeof (T) < sizeof (V) &&
|
||||||
|
std::is_signed<T>::value == std::is_signed<V>::value &&
|
||||||
|
std::is_floating_point<T>::value, V>::type v) {
|
||||||
|
CHECK_HARD (v <= std::numeric_limits<T>::max ());
|
||||||
|
CHECK_HARD (v >= std::numeric_limits<T>::lowest ());
|
||||||
|
CHECK_HARD (exactly_equal (remainder (v, 1), 0.0));
|
||||||
|
|
||||||
return static_cast<T> (v);
|
return static_cast<T> (v);
|
||||||
}
|
}
|
||||||
@ -97,8 +111,8 @@ trunc_cast (V v)
|
|||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
T
|
T
|
||||||
size_cast (const V v) {
|
size_cast (const V v) {
|
||||||
CHECK_HARD (std::numeric_limits<T>::min () <= v);
|
CHECK_HARD (std::numeric_limits<T>::lowest () <= v);
|
||||||
CHECK_HARD (std::numeric_limits<T>::max () >= v);
|
CHECK_HARD (std::numeric_limits<T>::max () >= v);
|
||||||
|
|
||||||
return static_cast<T> (v);
|
return static_cast<T> (v);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user