Home C Math Functions isinf() C isinf() Macro 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.
Call What 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 #define isinf(x) /* implementation-defined macro */ Parameters Parameter Description x Required. The floating value to classify (float, double, or long double).
Return Value Return Value Description Non-zero (true) When x is positive or negative infinity. 0 (false) When x is finite or NaN.
C Examples 1. Basic isinf 2. Overflow result 3. Reject infinity Example 1 — Basic Infinity Check Print 1 for infinity values and 0 for ordinary numbers.
#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 Include math.h. That provides isinf and INFINITY.Positive infinity. The first line prints 1.Negative infinity. The second line also prints 1.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.
#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 Start large. 1e308 is near the top of the double range.Multiply. The product overflows and becomes infinity.Classify. isinf(result) returns true.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.
#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 Imagine a broken sensor. The sample reading is infinity.Test with isinf. The macro returns true.Take the safe branch. Print a clear error message.Keep math healthy. Rejecting infinity early avoids spreading garbage through later calculations.Frequently Asked Questions What does isinf() do in C? isinf() returns non-zero when its argument is positive or negative infinity, otherwise 0.
What is the parameter of isinf()? x is required. It is the floating value you want to classify.
What does isinf() return? A non-zero value for infinity, or 0 for anything else including NaN and finite numbers.
Which header file does isinf() need? Include <math.h>. On GCC, link with -lm.
Is NaN the same as infinity? 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.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion