Boost logo

Boost :

Subject: Re: [boost] [math] potentian bug: iround throws, given double( numeric_limits<int>::min() )
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2011-10-20 17:03:55


2011/10/20 John Maddock <boost.regex_at_[hidden]>

> 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<http://www.boost.org/doc/libs/1_47_0/libs/numeric/conversion/doc/html/boost_numericconversion/improved_numeric_cast__.html>
>
> John.
>

I thought that was only for checking range. Or do you mean round(), and then
numeric_cast<>() instead of checking range manually in round_cast<>()?

Regards
Kris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk