Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isinf — C23 floating-point classification macro

`isinf(x)` from `<math.h>` is a classification macro that returns nonzero exactly when its real floating argument is positive or negative infinity. Finite values and every NaN produce zero.

Version: C23

Syntax

isinf(x)

isinf(x) from <math.h> is a classification macro that returns nonzero exactly when its real floating argument is positive or negative infinity. Finite values and every NaN produce zero.

The example tests INFINITY, -INFINITY, 1.0, and NAN, normalizing with != 0. Output 1 1 0 0 shows that both signs of infinity belong to the class, while an ordinary number and a not-a-number value do not.

The standard promises only a nonzero result, so do not infer the infinity’s sign from its magnitude; use signbit(x) for that purpose. The macro classifies a value after evaluation, so it detects an overflow result only if the implementation actually produced infinity. Use isfinite when both NaNs and infinities must be rejected together. When an argument is represented in a format wider than its semantic type, it is converted to the semantic type before classification; a finite excess-range value can therefore make isinf true.

Examples

#include <math.h>
#include <stdio.h>
int main(void){double values[]={INFINITY,-INFINITY,1.0,NAN};printf("%d %d %d %d\n",isinf(values[0])!=0,isinf(values[1])!=0,isinf(values[2])!=0,isinf(values[3])!=0);return 0;}

Result

1 1 0 0

The example tests `INFINITY`, `-INFINITY`, `1.0`, and `NAN`, normalizing with `!= 0`. Output `1 1 0 0` shows that both signs of infinity belong to the class, while an ordinary number and a not-a-number value do not.

Sources