C isless() Macro

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

Definition

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);
CallWhat 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.

Library declarations
C
#define isless(x, y) /* implementation-defined macro */

Parameters

ParameterDescription
xRequired. Left-hand floating value (float, double, or long double).
yRequired. Right-hand floating value to compare against.

Return Value

Return ValueDescription
Non-zero (true)When x is less than y.
0 (false)When the relation is not true, including many NaN cases.

C Examples

Example 1 — Basic Less-Than Check

Print 1 when the left value is smaller, otherwise print 0.

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

int main(void) {
    printf("%d\n", (int)isless(2.0, 9.0));
    printf("%d\n", (int)isless(5.0, 3.0));
    printf("%d\n", (int)isless(4.0, 4.0));
    return 0;
}

How It Works

  1. Include math.h. That provides the isless macro.
  2. True case. 2.0 is less than 9.0, so you see 1.
  3. False case. 5.0 is larger than 3.0, so you see 0.
  4. Equal values. Equal numbers are not less, so the third line is 0.

Example 2 — NaN Compare Stays Quiet

A less-than check with NaN returns 0 without raising invalid.

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

int main(void) {
    printf("%d\n", (int)isless(NAN, 1.0));
    printf("%d\n", (int)isless(1.0, NAN));
    return 0;
}

How It Works

  1. NaN is unordered. You cannot rank NaN below a normal number.
  2. Both sides fail. Whether NaN is on the left or right, the result is false.
  3. Print zeros. Both lines show 0.
  4. 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;
}

How It Works

  1. Store two values. a is 18.2 and b is 21.7.
  2. Ask isless. The macro says a is smaller.
  3. Pick with ternary. The chosen value is a.
  4. 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.

Next: islessequal()

Check whether one floating value is less than or equal to another.

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