C isfinite() Macro

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, isfinite() is a classification helper from <math.h>. It tells you whether a floating-point value is finite. Finite means the value is a real number you can work with — not infinity and not NaN. isfinite(3.5) is true. isfinite(INFINITY) is false.

You pass one floating-point argument. The result is non-zero (true) for finite values, including zero and normal numbers, and zero (false) for infinity or NaN. It is usually a macro (or macro-like function) that accepts float, double, or long double.

Syntax

Pass one floating-point value. Start with this call.

C
isfinite(3.5);
CallWhat it does
isfinite(3.5)Non-zero — 3.5 is finite.
isfinite(INFINITY)Zero — infinity is not finite.
isfinite(NAN)Zero — NaN is not finite.

Include <math.h>. Treat a non-zero result as true. Related checks: isinf(), isnan(), and the broader fpclassify().

Library declarations
C
int isfinite(real-floating x);

Parameters

ParameterDescription
xRequired. Any real floating type (float, double, or long double).

Return Value

Return ValueDescription
Non-zerox is finite (includes zero and normal / subnormal numbers).
Zerox is infinity or NaN.

C Examples

Example 1 — Finite vs Not Finite

Print yes or no for a few values.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%s\n", isfinite(3.5) ? "yes" : "no");
    printf("%s\n", isfinite(0.0) ? "yes" : "no");
    printf("%s\n", isfinite(INFINITY) ? "yes" : "no");
    return 0;
}

How It Works

  1. Include math.h. Provides isfinite and INFINITY.
  2. Ordinary number. 3.5 is finite.
  3. Zero counts. 0.0 is finite too.
  4. Infinity fails. INFINITY is not finite.

Example 2 — NaN Is Not Finite

Guard a calculation when the input might be invalid.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = 0.0 / 0.0;

    if (isfinite(x)) {
        printf("ok to use\n");
    } else {
        printf("bad value\n");
    }
    return 0;
}

How It Works

  1. Create NaN. 0.0 / 0.0 is NaN.
  2. Test. isfinite(x) is false.
  3. Branch. Skip math that would spread the bad value.
  4. Also catches inf. The same check rejects infinity.

Example 3 — Only Divide Finite Numbers

Check both sides before a sensitive operation.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double a = 10.0;
    double b = 2.0;

    if (isfinite(a) && isfinite(b) && b != 0.0) {
        printf("q = %.1f\n", a / b);
    } else {
        printf("skip\n");
    }
    return 0;
}

How It Works

  1. Validate inputs. Both a and b must be finite.
  2. Avoid / 0. Still check that b is not zero.
  3. Then divide. Safe path prints 5.0.
  4. Defense. Stops infinity and NaN from entering the formula.

Frequently Asked Questions

isfinite() returns non-zero when the value is finite, and zero when it is infinity or NaN.
x is required. It can be float, double, or long double.
Non-zero for finite values (including zero). Zero for infinity or NaN.
Include <math.h>.
It is a classification macro/function in math.h. Call it like a function; the library may implement it as a macro.

Next: isgreater()

Quiet floating-point greater-than comparison.

isgreater() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful