C isinf() Macro

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

Definition

In C, isinf() is a <math.h> classification macro. It tells you if a floating value is positive or negative infinity. True is non-zero; false is 0.

Infinity can appear after overflow, after dividing a non-zero number by zero in floating math, or after you build it with macros such as INFINITY. isinf() is the clear way to detect that special value.

Pass one real floating argument. Include <math.h>. Print the result as 0 or 1 with a cast to int when you want a simple display.

Syntax

Ask whether a value is infinity. Start with this call.

C
isinf(x);
CallWhat it does
isinf(INFINITY)Returns non-zero because the value is infinity.
isinf(-INFINITY)Also non-zero. Sign does not matter for this test.
isinf(3.14)Returns 0 because a normal finite number is not infinity.

Include <math.h>. On GCC, link with -lm. Pair this with isnan, isfinite, and isnormal when you classify floating results.

Library declarations
C
#define isinf(x) /* implementation-defined macro */

Parameters

ParameterDescription
xRequired. The floating value to classify (float, double, or long double).

Return Value

Return ValueDescription
Non-zero (true)When x is positive or negative infinity.
0 (false)When x is finite or NaN.

C Examples

Example 1 — Basic Infinity Check

Print 1 for infinity values and 0 for ordinary numbers.

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

int main(void) {
    printf("%d\n", (int)isinf(INFINITY));
    printf("%d\n", (int)isinf(-INFINITY));
    printf("%d\n", (int)isinf(42.0));
    return 0;
}

How It Works

  1. Include math.h. That provides isinf and INFINITY.
  2. Positive infinity. The first line prints 1.
  3. Negative infinity. The second line also prints 1.
  4. Finite number. A normal value such as 42.0 prints 0.

Example 2 — Catch an Overflow Result

A huge multiply can overflow to infinity. Detect that with isinf.

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

int main(void) {
    double huge = 1e308;
    double result = huge * huge;

    printf("%d\n", (int)isinf(result));
    return 0;
}

How It Works

  1. Start large. 1e308 is near the top of the double range.
  2. Multiply. The product overflows and becomes infinity.
  3. Classify. isinf(result) returns true.
  4. Print 1. The program reports the overflow as infinity.

Example 3 — Reject Infinity Before Use

Skip a value when it is not a usable finite reading.

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

int main(void) {
    double reading = INFINITY;

    if (isinf(reading)) {
        printf("bad reading\n");
    } else {
        printf("ok\n");
    }

    return 0;
}

How It Works

  1. Imagine a broken sensor. The sample reading is infinity.
  2. Test with isinf. The macro returns true.
  3. Take the safe branch. Print a clear error message.
  4. Keep math healthy. Rejecting infinity early avoids spreading garbage through later calculations.

Frequently Asked Questions

isinf() returns non-zero when its argument is positive or negative infinity, otherwise 0.
x is required. It is the floating value you want to classify.
A non-zero value for infinity, or 0 for anything else including NaN and finite numbers.
Include <math.h>. On GCC, link with -lm.
No. NaN means Not a Number. Use isnan() for NaN and isinf() for infinity.

Next: isless()

Check whether one floating value is strictly less than another.

isless() 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