From 9124791a5952665bb2aa9c7439c489147c5b4831 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 14 Jun 2012 18:31:58 +1000 Subject: [PATCH] Use lowest instead of min in casting checks --- types/casts.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) 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); }