Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOOST_TEST_EQ diagnostic for floating point types lacks precision #89

Open
Kojoley opened this issue May 15, 2021 · 3 comments
Open

BOOST_TEST_EQ diagnostic for floating point types lacks precision #89

Kojoley opened this issue May 15, 2021 · 3 comments

Comments

@Kojoley
Copy link
Contributor

Kojoley commented May 15, 2021

#include <boost/core/lightweight_test.hpp>
#include <limits>

int main()
{
    BOOST_TEST_EQ(0x9.d495182a99318p-13, 0x9.d495182a99308p-13);
    std::cerr.precision(std::numeric_limits<double>::max_digits10);
    std::cerr << 0x9.d495182a99318p-13 << " == " << 0x9.d495182a99308p-13 << '\n';
    return boost::report_errors();
}
prog.cc(5): test '0x9.d495182a99318p-13 == 0x9.d495182a99308p-13' ('0.0012' == '0.0012') failed in function 'int main()'
0.0012000000000000003 == 0.0011999999999999999
@glenfe
Copy link
Member

glenfe commented May 15, 2021

#include <boost/core/lightweight_test.hpp>
#include <limits>

int main()
{
    BOOST_LIGHTWEIGHT_TEST_OSTREAM.precision(std::numeric_limits<double>::max_digits10);
    BOOST_TEST_EQ(0x9.d495182a99318p-13, 0x9.d495182a99308p-13);
    return boost::report_errors();
}
prog.cc(7): test '0x9.d495182a99318p-13 == 0x9.d495182a99308p-13' ('0.0012000000000000003' == '0.0011999999999999999') failed in function 'int main()'

@pdimov
Copy link
Member

pdimov commented May 15, 2021

It probably makes sense to set the precision before printing floating point, but we need to restore it afterwards, and digits10 is C++11, so it's a bit of a hassle. Although maybe not so much.

@pdimov
Copy link
Member

pdimov commented May 15, 2021

Ah wait, it's not C++11. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants