In C, isless() is a <math.h> comparison macro. It answers a yes/no question: x is less than y. A true answer is a non-zero value (often printed as 1). A false answer is 0.
Unlike a raw x < y compare, isless() is designed so that NaN does not raise an invalid floating-point exception. If either value is NaN, the answer is false (except for special cases covered by related macros such as isunordered).
Pass two real floating values. Include <math.h>. Print the result with %d after casting to int if you want a clear 0 or 1 on the screen.
Syntax
Compare two floating-point values. Start with this call.
C
isless(x, y);
Call
What it does
isless(5.0, 3.0)
Returns non-zero because 2.0 is less than 9.0.
isless(2.0, 9.0)
Returns 0 because 5.0 is not less than 3.0.
isless(NAN, 1.0)
With NaN involved, the result is 0 (false) without raising an invalid exception from this macro.
Include <math.h>. On GCC, link with -lm. Prefer this macro over x < y when either side might be NaN and you do not want an invalid exception.
NaN is unordered. You cannot rank NaN below a normal number.
Both sides fail. Whether NaN is on the left or right, the result is false.
Print zeros. Both lines show 0.
Safer than <. This macro avoids the invalid exception a raw < can raise.
Example 3 — Pick the Smaller Reading
Choose the lower of two temperatures with a safe compare.
C
#include <stdio.h>
#include <math.h>
int main(void) {
double a = 18.2;
double b = 21.7;
double low = isless(a, b) ? a : b;
printf("%.1f\n", low);
return 0;
}
Output
18.2
How It Works
Store two values. a is 18.2 and b is 21.7.
Ask isless. The macro says a is smaller.
Pick with ternary. The chosen value is a.
Print the result. The program shows 18.2.
Frequently Asked Questions
isless() is a math.h comparison macro. It checks whether x is less than y.
x and y are required floating values. They are the two numbers you want to compare.
A non-zero int-like result for true, or 0 for false. Beginners often print it as 0 or 1.
Include <math.h>. On GCC, link with -lm.
The macro is quieter with NaN: it does not raise an invalid floating-point exception the way a plain relational operator can. Use related macros like isgreater / islessequal when you need the other relation.