c++ - 使用空的 boost::accumulators

标签 c++ boost nan boost-accumulators

如何检查一个空的 boost::accumulators acc 与否?

例如:

if (acc.isEmpty())//I don't know what function here
 return 0;
else 
 return boost::accumulators::mean(acc).

因为如果它是空的,我得到 NaN for boost::accumulators::mean(acc)。

最佳答案

您可以使用累加器 count :

if (boost::accumulators::count(acc) == 0)//I don't know what function here
 return 0;
else 
 return boost::accumulators::mean(acc);

或者,您可以通过调用 std::isnan 来简单地检查它是否为 nan :

 if(std::isnan(boost::accumulators::mean(acc))
    return 0;
 else
    return boost::accumulators::mean(acc);

关于c++ - 使用空的 boost::accumulators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28523949/

相关文章:

php - javascript sum 返回 NaN 错误

pandas - 在 Pandas 中替换名称时忽略 NaN 值

c++ - 我编译的标准库中的 std::endl 在哪里?

c++ - Qt 5.2 和 iOS : "Nothing to be done"

c++ - 使用 GLUT 和 C++ 在 Open GL 中提供 Material 属性帮助

c++ - 使用 boost::geometry::within 编译错误

c - 我如何让 printf 在 w32 上使用 'nan'?

c++ - 显式调用析构函数

c++ - 如何让协程始终在同一个线程中工作?

c++ - boost::asio 在使用成员接受器而不是新接受器时崩溃