Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isfinite — C23 floating-point classification macro

`isfinite(x)` from `<math.h>` is a classification macro: it returns nonzero exactly when its real floating argument has a finite value. Normal numbers, subnormal numbers, and both signed zeros are finite; infinities and NaNs are not.

Version: C23

Syntax

isfinite(x)

isfinite(x) from <math.h> is a classification macro: it returns nonzero exactly when its real floating argument has a finite value. Normal numbers, subnormal numbers, and both signed zeros are finite; infinities and NaNs are not.

The example tests 1.0, -0.0, INFINITY, and NAN, normalizing with != 0. Output 1 1 0 0 confirms that the sign of zero does not affect finiteness, while the infinite and not-a-number special values are rejected.

Do not assume a true result equals exactly 1; consume it as a logical condition. The macro classifies an already computed value, so it cannot prevent earlier overflow, and finiteness alone does not establish an application’s domain validity. Use isnan and isinf when NaN and infinity must be distinguished. 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 become an infinity.

Examples

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

Result

1 1 0 0

The example tests `1.0`, `-0.0`, `INFINITY`, and `NAN`, normalizing with `!= 0`. Output `1 1 0 0` confirms that the sign of zero does not affect finiteness, while the infinite and not-a-number special values are rejected.

Sources