|
Boost : |
Subject: Re: [boost] [math] potentian bug: iround throws, given double( numeric_limits<int>::min() )
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-10-20 12:11:29
> Ah, thanks for a confirmation...
>
> I am interested in a resolution here, which I would like to implement in a
> function I wrote as a more general iround; I call it round_cast():
>
> <code>
> template < class R, class T, class Policy >
> inline R round_cast( T const& x, Policy const& pol )
> {
> BOOST_MATH_STD_USING
> T r = boost::math::round(x,pol);
> if( r > boost::integer_traits<R>::const_max || r <
> boost::integer_traits<R>::const_min )
> return static_cast<R>( boost::math::policies::raise_rounding_error(
> "cz::ar::round_cast<target_type,%1%>(%1%)", 0, x, pol ) );
> return static_cast<R>(r);
> }
>
> template < class R, class T >
> inline R round_cast( T const& x )
> {
> return round_cast<R>( x, boost::math::policies::policy<>() );
> }
> </code>
Isn't that more or less the same as:
http://www.boost.org/doc/libs/1_47_0/libs/numeric/conversion/doc/html/boost_numericconversion/improved_numeric_cast__.html
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk