Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2737: Rounding failed for -0.5
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-10 16:15:00
#2737: Rounding failed for -0.5
------------------------------------------+---------------------------------
Reporter: kennant.tom_at_[hidden] | Owner: dgregor
Type: Bugs | Status: closed
Milestone: Boost 1.38.0 | Component: numeric
Version: Boost 1.37.0 | Severity: Problem
Resolution: invalid | Keywords:
------------------------------------------+---------------------------------
Comment(by steven_watanabe):
The common method is not provided.
Round to even has better statistical properties.
It would look something like this based
on RoundEven
{{{
template<class S>
struct RoundCommon
{
typedef S source_type ;
typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type
argument_type ;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor ;
using std::ceil ;
#endif
// only works inside the range not at the boundaries
S prev = floor(s);
S next = ceil(s);
S rt = (s - prev) - (next - s); // remainder type
S const zero(0.0);
S const two(2.0);
if ( rt < zero )
return prev;
else if ( rt > zero )
return next;
else if ( prev < zero )
return prev;
else
return next;
}
typedef mpl::integral_c< std::float_round_style, std::round_to_nearest>
round_style ;
} ;
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2737#comment:3> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC