Home C Math Functions isnormal() C isnormal() Macro Definition In C, isnormal() is a <math.h> classification macro. It tells you if a floating value is a normal number. True is non-zero; false is 0.
A normal number is a regular finite value that is not zero, not a tiny subnormal, not infinity, and not NaN. Most everyday measurements you store in double are normal.
Pass one real floating argument. Include <math.h>. Print the result as 0 or 1. Combine it with isnan, isinf, and isfinite when you classify results.
Syntax Ask whether a value is a normal number. Start with this call.
Call What it does isnormal(3.5)Returns non-zero because 3.5 is a normal finite number. isnormal(0.0)Returns 0 because zero is not classified as normal. isnormal(NAN)Returns 0 because NaN is not a normal number.
Include <math.h>. On GCC, link with -lm. Zero, subnormals, infinities, and NaNs all fail this test.
Library declarations #define isnormal(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 a normal floating number. 0 (false) When x is zero, subnormal, infinity, or NaN.
C Examples 1. Basic isnormal 2. Filter inputs 3. Contrast finite Example 1 — Basic Normal Check Print 1 for normal numbers and 0 for special cases.
#include <stdio.h>
#include <math.h>
int main(void) {
printf("%d\n", (int)isnormal(3.5));
printf("%d\n", (int)isnormal(0.0));
printf("%d\n", (int)isnormal(INFINITY));
printf("%d\n", (int)isnormal(NAN));
return 0;
} How It Works Include math.h. That provides the classification macros.Normal value. 3.5 prints 1.Zero fails. Zero is finite but not normal, so print 0.Special values fail. Infinity and NaN also print 0.Example 2 — Accept Only Normal Inputs Reject zero and special values before a calculation that needs a solid magnitude.
#include <stdio.h>
#include <math.h>
int main(void) {
double x = 2.5;
if (isnormal(x)) {
printf("ready\n");
} else {
printf("skip\n");
}
return 0;
} How It Works Pick a sample. x is 2.5.Ask isnormal. The macro returns true.Continue the work. Print ready.Why filter. Normal values are the everyday finite numbers your formula expects.Example 3 — Contrast with isfinite Zero is finite, but isnormal still returns 0.
#include <stdio.h>
#include <math.h>
int main(void) {
double z = 0.0;
printf("isfinite=%d\n", (int)isfinite(z));
printf("isnormal=%d\n", (int)isnormal(z));
return 0;
} How It Works Use zero. Zero is a valid floating value.Check isfinite. Zero is finite, so that line prints 1.Check isnormal. Zero is not normal, so that line prints 0.Choose carefully. Pick the macro that matches your rule.Frequently Asked Questions What does isnormal() do in C? isnormal() returns non-zero when its argument is a normal floating number, otherwise 0.
What is the parameter of isnormal()? x is required. It is the floating value you want to classify.
What does isnormal() return? A non-zero value for normal numbers, or 0 for zero, subnormals, infinities, and NaNs.
Which header file does isnormal() need? Include <math.h>. On GCC, link with -lm.
How is isnormal() different from isfinite()? isfinite() is true for zeros and many tiny values. isnormal() is true only for normal finite numbers.
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