C islessequal() Macro

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

Definition

In C, islessequal() is a <math.h> comparison macro. It answers a yes/no question: x is less than or equal to y. A true answer is a non-zero value (often printed as 1). A false answer is 0.

Unlike a raw x <= y compare, islessequal() 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
islessequal(x, y);
CallWhat it does
islessequal(5.0, 3.0)Returns non-zero because 2.0 is less than 9.0 (also true when equal).
islessequal(2.0, 9.0)Returns 0 because 5.0 is greater than 3.0.
islessequal(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 islessequal(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 or equal to y.
0 (false)When the relation is not true, including many NaN cases.

C Examples

Example 1 — Basic Less-or-equal Check

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

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

int main(void) {
    printf("%d\n", (int)islessequal(2.0, 9.0));
    printf("%d\n", (int)islessequal(4.0, 4.0));
    printf("%d\n", (int)islessequal(8.0, 1.0));
    return 0;
}

How It Works

  1. Include math.h. That declares the comparison macro.
  2. Strictly less. 2.0 <= 9.0 is true, so print 1.
  3. Equal values. Equal numbers also count, so the second line is 1.
  4. Larger left side. When the left value is bigger, the result is 0.

Example 2 — NaN Fails the Relation

Less-or-equal with NaN returns 0 on both sides.

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

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

How It Works

  1. Remember NaN. NaN is unordered, so ordinary relations fail.
  2. Left NaN. The first call prints 0.
  3. Right NaN. The second call also prints 0.
  4. Quiet path. The macro avoids raising invalid on these compares.

Example 3 — Stay Under an Upper Limit

Accept a load only when it is at or below a safe maximum.

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

int main(void) {
    double load = 49.5;
    double max = 50.0;

    if (islessequal(load, max)) {
        printf("safe\n");
    } else {
        printf("overload\n");
    }

    return 0;
}

How It Works

  1. Read a load. The sample load is 49.5.
  2. Set a maximum. The allowed peak is 50.0.
  3. Compare carefully. islessequal is true for this pair.
  4. Report safety. The program prints safe.

Frequently Asked Questions

islessequal() is a math.h comparison macro. It checks whether x is less than or equal to 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 / isless when you need the other relation.

Next: islessgreater()

Check whether two floating values are ordered and unequal.

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