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) (分类浮点值(宏/函数))