C++ Reference: Standard C++ Library reference: C Library: cmath: isunordered

C++官网参考链接:https://cplusplus.com/reference/cmath/isunordered/

宏 
<cmath> <ctgmath>
isunordered
C99
宏    
isunordered(x,y)
C++11
函数    
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异常。
C99
在C语言中,这被实现为一个返回int值的宏。xy的类型都应为float、double或long double。
C++11
在C++中,它是通过每个浮点类型(floating-point type)的函数重载来实现的,每个浮点类型都返回bool值。

形参
x,y
用来检查它们是无序的值。

返回值
如果xy是NaN,则为true(1)。
否则为false(0)。

用例
/* 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;

输出:


版权声明:本文为weixin_40186813原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。