C isgreaterequal() Macro

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

Definition

In C, isgreaterequal() is a <math.h> comparison macro. It answers a yes/no question: x is greater 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, isgreaterequal() 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
isgreaterequal(x, y);
CallWhat it does
isgreaterequal(5.0, 3.0)Returns non-zero because 5.0 is greater than 3.0 (also true when equal).
isgreaterequal(2.0, 9.0)Returns 0 because 2.0 is smaller than 9.0.
isgreaterequal(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 isgreaterequal(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 greater than or equal to y.
0 (false)When the relation is not true, including many NaN cases.

C Examples

Example 1 — Basic Greater-or-Equal Check

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

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

int main(void) {
    printf("%d\n", (int)isgreaterequal(5.0, 3.0));
    printf("%d\n", (int)isgreaterequal(4.0, 4.0));
    printf("%d\n", (int)isgreaterequal(1.0, 7.0));
    return 0;
}

How It Works

  1. Include math.h. That declares the comparison macro.
  2. Strictly greater. 5.0 >= 3.0 is true, so print 1.
  3. Equal values. Equal numbers also count, so the second line is 1.
  4. Smaller left side. When the left value is smaller, the result is 0.

Example 2 — NaN Makes the Check False

Any compare with NaN fails quietly for this macro.

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

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

How It Works

  1. NaN is unordered. NaN is not greater than, less than, or equal to another value in the usual sense.
  2. Two NaNs. Even NAN compared with itself is false here.
  3. Normal vs NaN. A normal number against NaN is also false.
  4. No invalid raise. The macro is meant to avoid raising invalid on this NaN compare path.

Example 3 — Pass a Minimum Threshold

Accept a score only when it meets or beats a cutoff.

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

int main(void) {
    double score = 72.5;
    double pass = 70.0;

    if (isgreaterequal(score, pass)) {
        printf("pass\n");
    } else {
        printf("retry\n");
    }

    return 0;
}

How It Works

  1. Set a score. The sample score is 72.5.
  2. Set a cutoff. Passing needs at least 70.0.
  3. Use the macro. isgreaterequal is true for 72.5 against 70.0.
  4. Print the decision. The program prints pass.

Frequently Asked Questions

isgreaterequal() is a math.h comparison macro. It checks whether x is greater 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 isless / isgreater when you need the other relation.

Next: isinf()

Test whether a floating value is positive or negative infinity.

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