Opened 8 years ago

Closed 8 years ago

#10066 closed Bugs (fixed)

math::round broken for some integer types/values

Reported by: andrew.bell.ia@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

The current code takes the input (which may be an int type) and adds/subtracts .5f, which may cause precision to be lost as the integer is converted to a float. math::round should essentially be a noop when the input type is integral.

===========

#include <iostream>
#include <iomanip>
#include <math.h>
#include <boost/math/special_functions/round.hpp>

int main()
{
    long l = -1230695498;

    std::cerr << "boost::math::lround(l) = " << std::setprecision(12) <<
        boost::math::lround(l) << "\n";
    std::cerr << "::lround(l) = " <<std::setprecision(12) <<
        ::lround(l) << "\n";
}

Change History (1)

comment:1 by John Maddock, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.