Opened 8 years ago
Closed 8 years ago
#10066 closed Bugs (fixed)
math::round broken for some integer types/values
Reported by: | 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"; }
Note:
See TracTickets
for help on using tickets.
Fixed in Git develop. See https://github.com/boostorg/math/commit/e6996e118850881ca56b7a9a165fe4f38ab843bc