Opened 11 years ago

#6047 new Feature Requests

functions round_cast and trunc_cast

Reported by: 1czajnik@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

The functions are general versions of iround, and alike functions.

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<>() );
}

Analogically for trunc()...

Attachments (2)

ticket6047_round_trunc_01242013.patch (2.3 KB ) - added by genevivewoo@… 10 years ago.
round & trunc.hpp
ticket6047_round_trunc_01242013.diff (2.3 KB ) - added by Evelyn Wu <genevivewoo@…> 10 years ago.

Download all attachments as: .zip

Change History (2)

by genevivewoo@…, 10 years ago

round & trunc.hpp

by Evelyn Wu <genevivewoo@…>, 10 years ago

Note: See TracTickets for help on using tickets.