diff --git a/types/casts.hpp b/types/casts.hpp index 33f5ff24..ddce2f35 100644 --- a/types/casts.hpp +++ b/types/casts.hpp @@ -78,9 +78,23 @@ namespace detail { template T _trunc_cast (const typename std::enable_if::value == std::is_signed::value, V>::type v) { - CHECK_HARD (v <= std::numeric_limits::max ()); - checK_hard (v >= std::numeric_limits::min ()); + std::is_signed::value == std::is_signed::value && + std::is_integral::value, V>::type v) { + CHECK_HARD (v <= std::numeric_limits::max ()); + CHECK_HARD (v >= std::numeric_limits::lowest ()); + + return static_cast (v); + } + + + template + T + _trunc_cast (const typename std::enable_if::value == std::is_signed::value && + std::is_floating_point::value, V>::type v) { + CHECK_HARD (v <= std::numeric_limits::max ()); + CHECK_HARD (v >= std::numeric_limits::lowest ()); + CHECK_HARD (exactly_equal (remainder (v, 1), 0.0)); return static_cast (v); } @@ -97,8 +111,8 @@ trunc_cast (V v) template T size_cast (const V v) { - CHECK_HARD (std::numeric_limits::min () <= v); - CHECK_HARD (std::numeric_limits::max () >= v); + CHECK_HARD (std::numeric_limits::lowest () <= v); + CHECK_HARD (std::numeric_limits::max () >= v); return static_cast (v); }