<cmath> <ctgmath>

isunordered

isunordered(x,y)
函式
bool isunordered (float x      , float y);bool isunordered (double x     , double y);bool isunordered (long double x, long double y);
是否無序
返回 xy 是否為無序值

如果一個或兩個引數是NaN,則這些引數是無序的,函式返回 true。在任何情況下,此函式都不會引發 FE_INVALID 異常。

在 C 語言中,這被實現為一個返回 int 值的宏。 xy 的型別都應為 floatdoublelong double
在 C++ 中,它透過針對每種浮點型別的函式過載實現,每個過載都返回一個 bool 值。

引數

x, y
要檢查其是否無序的值。

返回值

如果 xy 中任意一個是NaN,則為 true (1)。
否則為 false (0)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* isunordered example */
#include <stdio.h>      /* printf */
#include <math.h>       /* isunordered, sqrt */

int main ()
{
  double result;
  result = sqrt (-1.0);

  if (isunordered(result,0.0))
    printf ("sqrt(-1.0) and 0.0 cannot be ordered");
  else
    printf ("sqrt(-1.0) and 0.0 can be ordered");

  return 0;
}

輸出

sqrt(-1.0) and 0.0 cannot be ordered


另見