Ticket #6047: ticket6047_round_trunc_01242013.patch
File ticket6047_round_trunc_01242013.patch, 2.3 KB (added by , 10 years ago) |
---|
-
trunc.hpp
16 16 17 17 namespace boost{ namespace math{ 18 18 19 template < class T, class TargetType, class Policy > 20 inline TargetType trunc_cast(T const& x, Policy const& pol) 21 { 22 BOOST_STATIC_ASSERT(std::numeric_limits<TargetType>::is_specialized); 23 T r = trunc(x); 24 if ((r> (std::numeric_limits<TargetType>::max)()) || 25 (r < (std::numeric_limits<TargetType>::min)())) 26 return policies::raise_rounding_error 27 ("boost::math::round_cast<%1%,TargetType>(%%1%%)>", 28 "Value %1% exceeds the numeric limits", 29 r, 30 0, 31 pol); 32 return static_cast<TargetType> (r); 33 34 } 35 36 template <class T, class TargetType> 37 inline TargetType trunc_cast(T const& x) 38 { 39 typedef typename policies::policy< 40 boost::math::policies::rounding_error<policies::throw_on_error> 41 > Policy; 42 return trunc_cast<T, TargetType, Policy>(x, Policy()); 43 } 44 45 19 46 template <class T, class Policy> 20 47 inline T trunc(const T& v, const Policy& pol) 21 48 { -
round.hpp
14 14 #include <boost/math/policies/error_handling.hpp> 15 15 #include <boost/math/special_functions/fpclassify.hpp> 16 16 17 17 18 namespace boost{ namespace math{ 18 19 20 21 template < class T, class TargetType, class Policy > 22 inline TargetType round_cast(T const& x, Policy const& pol) 23 { 24 BOOST_STATIC_ASSERT(std::numeric_limits<TargetType>::is_specialized); 25 T r = round(x); 26 if ((r> (std::numeric_limits<TargetType>::max)()) || 27 (r < (std::numeric_limits<TargetType>::min)())) 28 return policies::raise_rounding_error 29 ("boost::math::round_cast<%1%,TargetType>(%%1%%)>", 30 "Value %1% exceeds the numeric limits", 31 r, 32 0, 33 pol); 34 return static_cast<TargetType> (r); 35 36 } 37 38 template <class T, class TargetType> 39 inline TargetType round_cast(T const& x) 40 { 41 typedef typename policies::policy< 42 boost::math::policies::rounding_error<policies::throw_on_error> 43 > Policy; 44 return round_cast<T, TargetType, Policy>(x, Policy()); 45 } 46 19 47 template <class T, class Policy> 20 48 inline T round(const T& v, const Policy& pol) 21 49 {