【发布时间】:2014-12-23 03:06:37
【问题描述】:
arma::max 和 arma::min 在输入包含所有 NAN 值的向量时似乎提供了意想不到的结果。 min/max 函数不是返回 NaN,而是返回 +/- inf。这是库中的错误,还是预期的行为?
#include <armadillo>
#include <numeric>
#include <iostream>
int main() {
arma::vec v(2);
v[0] = std::numeric_limits<double>::quiet_NaN();
v[1] = std::numeric_limits<double>::quiet_NaN();
std::cout << arma::max(v) << " " << arma::min(v) << std::endl;
// output: -inf inf
std::cout << std::max(v[0], v[1]) << " " << std::min(v[0],v[1]) << std::endl;
// output: -inf inf
}
供参考,GNU octave:
octave:1> min([nan,nan])
ans = NaN
octave:2> max([nan,nan])
ans = NaN
【问题讨论】: