2014-12-22 22 views
1

arma :: max和arma :: min在餵食含有所有NAN值的載體時似乎提供了意想不到的結果。 min/max函數不是返回NaN,而是返回+/- inf。這是庫中的錯誤還是預期的行爲?犰狳最大/最小功能處理NaN?

#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:1> min([nan,nan]) 
ans = NaN 
octave:2> max([nan,nan]) 
ans = NaN 

回答

2

這是給每一個庫作爲。 Armadillo doesn't seem to document their choice,但這是一個完全合理和有效的。我沒有理由認爲它是一個庫錯誤。

+1

我想如果你用空序列來調用它,你會得到同樣的結果。 –