有关BOOST_CHECK_CLOSE_FRACTION的问题 [英] Problem with BOOST_CHECK_CLOSE_FRACTION

查看:111
本文介绍了有关BOOST_CHECK_CLOSE_FRACTION的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Boost :: Test库,我想检查实际的百分比值是否接近预期值:

I'm using the Boost::Test library, and I am trying to check if an actual percent value is close to the expected value:

BOOST_CHECK_CLOSE_FRACTION(
    items[i].ExpectedPercent,
    items[i].ActualCount / totalCount,
    0.05);

由于某种原因,即使值足够接近,此检查也会失败:

For some reason this check fails even when the values are close enough:

difference between items[i].ExpectedPercent{0.40000000000000002}
   and items[i].ActualCount / totalReturned{0.42999999999999999}
                                    exceeds 0.050000000000000003

这是Boost的问题还是我使用Boost的问题?

Is this a problem with Boost or a problem with how I am using Boost?

推荐答案

经过一些测试,结果证明BOOST_CHECK_CLOSE_FRACTION的文档不正确。

After some testing, it turns out that the documentation for BOOST_CHECK_CLOSE_FRACTION is incorrect. The tolerance should be specified as a fraction of the expected value.

所以,TFAE:

BOOST_CHECK(abs(x - y) < (min(x, y) * 0.1));
BOOST_CHECK_CLOSE(x, y, 10);
BOOST_CHECK_CLOSE_FRACTION(x, y, 0.1);

这篇关于有关BOOST_CHECK_CLOSE_FRACTION的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆