Using std::setprecision to get the right precision for double to string conversion. by getvictor · Pull Request #8302 · osquery/osquery
Fixes #8301
boost::lexical_cast was not using the right precision for double-to-string conversion.
Switched to using std::ostringstream.
getvictor
marked this pull request as ready for review
| std::string operator()(const double& d) const { | ||
| std::string s{boost::lexical_cast<std::string>(d)}; | ||
| std::ostringstream ss; | ||
| ss << std::setprecision(std::numeric_limits<double>::digits10 + 1) << d; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it 16 because that's the case for most doubles?
Double values have between 15 and 18 digits of precision, with most double values having at least 16 significant digits. (source)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left one question.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters