Index: trunc.hpp =================================================================== --- trunc.hpp (revision 82592) +++ trunc.hpp (working copy) @@ -16,6 +16,33 @@ namespace boost{ namespace math{ +template < class T, class TargetType, class Policy > +inline TargetType trunc_cast(T const& x, Policy const& pol) +{ +BOOST_STATIC_ASSERT(std::numeric_limits::is_specialized); +T r = trunc(x); +if ((r> (std::numeric_limits::max)()) || + (r < (std::numeric_limits::min)())) + return policies::raise_rounding_error + ("boost::math::round_cast<%1%,TargetType>(%%1%%)>", + "Value %1% exceeds the numeric limits", + r, + 0, + pol); + return static_cast (r); + +} + +template +inline TargetType trunc_cast(T const& x) +{ + typedef typename policies::policy< + boost::math::policies::rounding_error + > Policy; + return trunc_cast(x, Policy()); +} + + template inline T trunc(const T& v, const Policy& pol) { Index: round.hpp =================================================================== --- round.hpp (revision 82592) +++ round.hpp (working copy) @@ -14,8 +14,36 @@ #include #include + namespace boost{ namespace math{ + +template < class T, class TargetType, class Policy > +inline TargetType round_cast(T const& x, Policy const& pol) +{ + BOOST_STATIC_ASSERT(std::numeric_limits::is_specialized); + T r = round(x); + if ((r> (std::numeric_limits::max)()) || + (r < (std::numeric_limits::min)())) + return policies::raise_rounding_error + ("boost::math::round_cast<%1%,TargetType>(%%1%%)>", + "Value %1% exceeds the numeric limits", + r, + 0, + pol); + return static_cast (r); + +} + +template +inline TargetType round_cast(T const& x) +{ + typedef typename policies::policy< + boost::math::policies::rounding_error + > Policy; + return round_cast(x, Policy()); +} + template inline T round(const T& v, const Policy& pol) {