std::isunordered
來自 cppreference.com
定義於標頭檔案 <cmath> |
||
(1) | ||
bool isunordered( float x, float y ); bool isunordered( double x, double y ); |
(C++11 起) (直至 C++23) |
|
constexpr bool isunordered( /* floating-point-type */ x, /* floating-point-type */ y ); |
(C++23 起) | |
定義於標頭檔案 <cmath> |
||
template< class Arithmetic1, class Arithmetic2 > bool isunordered( Arithmetic1 x, Arithmetic2 y ); |
(A) | (C++11 起) (自 C++23 起為 constexpr) |
1) 確定浮點數 x 和 y 是否無序,即其中一個或兩個是 NaN,因此無法進行有意義的比較。 庫為所有 cv-unqualified 浮點型別提供了引數 x 和 y 的過載。(C++23 起)
A) 為所有其他算術型別組合提供了附加過載。
目錄 |
[編輯] 引數
x, y | - | 浮點數或整數值 |
[編輯] 返回值
如果 x 或 y 是 NaN,則為 true,否則為 false。
[編輯] 注意
不要求嚴格按照 (A) 提供額外的過載。它們只需足以確保對於其第一個引數 num1 和第二個引數 num2
|
(直至 C++23) |
如果 num1 和 num2 具有算術型別,則 std::isunordered(num1, num2) 具有與 std::isunordered(static_cast</*common-floating-point-type*/>(num1), 如果不存在具有最高等級和次等級的浮點型別,則過載決議不會從提供的過載中產生可用的候選函式。 |
(C++23 起) |
[編輯] 示例
執行此程式碼
#include <cmath> #include <iostream> #define SHOW_UNORDERED(x, y) \ std::cout << std::boolalpha << "isunordered(" \ << #x << ", " << #y << "): " \ << std::isunordered(x, y) << '\n' int main() { SHOW_UNORDERED(10, 01); SHOW_UNORDERED(INFINITY, NAN); SHOW_UNORDERED(INFINITY, INFINITY); SHOW_UNORDERED(NAN, NAN); }
輸出
isunordered(10, 01): false isunordered(INFINITY, NAN): true isunordered(INFINITY, INFINITY): false isunordered(NAN, NAN): true
[編輯] 參閱
(C++11) |
對給定浮點值進行分類 (函式) |
(C++11) |
檢查給定數字是否為 NaN (函式) |
C 文件 中關於 isunordered 的內容
|