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

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

宏/函数
<cmath> <ctgmath>
isinf 
C99
宏    
isinf(x)
C++11
函数
bool isinf(float x);
bool isinf(double x);
bool isinf(long double x);
是一个无穷值 
返回x是否为无穷值(正无穷值或负无穷值)。
C99
在C语言中,这被实现为一个返回int值的宏。x的类型应为float、double或long double。
C++11
在C++中,它是通过每个浮点类型(floating-point type)的函数重载来实现的,每个浮点类型都返回bool值。

形参
x
一个浮点值。 

返回值
如果x是无穷值,则为非0值(true);否则为0(false)。

用例
/* isinf example */
#include <stdio.h>      /* printf */
#include <math.h>       /* isinf, sqrt */

int main()
{
  printf ("isinf(0.0)       : %d\n",isinf(0.0));
  printf ("isinf(1.0/0.0)   : %d\n",isinf(1.0/0.0));
  printf ("isinf(-1.0/0.0)  : %d\n",isinf(-1.0/0.0));
  printf ("isinf(sqrt(-1.0)): %d\n",isinf(sqrt(-1.0)));
  return 0;
}
输出:

另请参考
isfinite    Is finite value (macro) (是有限值(宏/函数)) 
isnan    Is Not-A-Number (macro/function) (不是一个数(宏/函数)) 
isnormal    Is normal (macro/function) (是正常的(宏/函数)) 
fpclassify    Classify floating-point value (macro/function) (分类浮点值(宏/函数)) 


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