C++ std::isgreaterequal() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cmath>

Definition

In C++, std::isgreaterequal(x, y) asks "is x greater than or equal to y?" It is the quiet version of x >= y. isgreaterequal(2, 2) is true, while isgreater(2, 2) is false.

When a value is NaN, the answer is false, and no floating-point exception is raised. This is useful in loops over data that may have missing values, such as exam scores or sensor readings.

std::isgreaterequal() is declared in <cmath> and is part of the group Classification and comparison. These tools ask what kind of number you have: normal, zero, infinite, or NaN. In C++ they are ordinary overloaded functions in std, not macros.

Syntax

Include <cmath> and call std::isgreaterequal. Start with these lines.

C++
bool a = std::isgreaterequal(3.0, 2.0);   // true
bool b = std::isgreaterequal(2.0, 2.0);   // true (equal is allowed)
bool c = std::isgreaterequal(1.0, 2.0);   // false
CallWhat it does
std::isgreaterequal(3.0, 2.0)3 is bigger. Returns true.
std::isgreaterequal(2.0, 2.0)Equal values count. Returns true.
std::isgreaterequal(std::nan(""), 1.0)One value is NaN. Returns false.

The result is a bool. Add std::boolalpha before printing to see true or false instead of 1 or 0.

Library declarations
C++
bool isgreaterequal(float x, float y);
bool isgreaterequal(double x, double y);
bool isgreaterequal(long double x, long double y);
// plus overloads for mixed and integer arguments

Parameters

ParameterDescription
xRequired. The first number to compare. It can be float, double, long double, or an integer type.
yRequired. The second number to compare.

Return Value

Return ValueDescription
truex is greater than or equal to y.
falsex is less than y, or one of them is NaN.

C++ Examples

Example 1 — Compare Several Pairs

Test bigger, equal, smaller, and NaN pairs. The equal pair is the one that differs from isgreater().

C++
#include <cmath>
#include <iostream>

struct Pair {
    const char* label;
    double x;
    double y;
};

int main() {
    std::cout << std::boolalpha;
    Pair pairs[] = {
        {"5 vs 3", 5, 3},
        {"4 vs 4", 4, 4},
        {"3 vs 5", 3, 5},
        {"0.5 vs 0.25", 0.5, 0.25},
        {"1 vs NaN", 1, std::nan("")}
    };

    for (const Pair& p : pairs) {
        std::cout << p.label << ": " << std::isgreaterequal(p.x, p.y) << '\n';
    }
    return 0;
}

How It Works

  1. The loop gives each pair to isgreaterequal() and prints the answer next to its label.
  2. 5 vs 3 and 0.5 vs 0.25 have a bigger first value, so they are true. 4 vs 4 is also true because equal is allowed.
  3. 3 vs 5 is false. The pair with a NaN is false too, as no number is greater than or equal to NaN.

Example 2 — Check a Pass Mark

A score of 50 or more passes. One student has no score yet (NaN), and that student must not pass.

C++
#include <cmath>
#include <iostream>

int main() {
    std::cout << std::boolalpha;
    double scores[] = {49.5, 50.0, 72.25, std::nan("")};

    for (double s : scores) {
        std::cout << "score " << s << " passed: "
                  << std::isgreaterequal(s, 50.0) << '\n';
    }
    return 0;
}

How It Works

  1. Each score is compared with the pass mark 50 by isgreaterequal(s, 50.0).
  2. 49.5 is just below the mark, so it fails. 50 is exactly on the mark, and equal counts, so it passes. 72.25 passes easily.
  3. The missing score is NaN, so the answer is false. On some systems the NaN is printed as -nan.

Example 3 — Check if Two Numbers Are Close

Decimals are rarely exactly equal. Use isgreaterequal(tolerance, difference) to ask whether the difference is small enough.

C++
#include <cmath>
#include <iostream>

int main() {
    std::cout << std::boolalpha;
    double tolerance = 0.001;

    double a1 = 0.1 + 0.2;
    std::cout << "0.1 + 0.2 vs 0.3: exact " << (a1 == 0.3) << ", close "
              << std::isgreaterequal(tolerance, std::fabs(a1 - 0.3)) << '\n';

    std::cout << "1.0 vs 1.0004: close "
              << std::isgreaterequal(tolerance, std::fabs(1.0 - 1.0004)) << '\n';
    std::cout << "1.0 vs 1.01: close "
              << std::isgreaterequal(tolerance, std::fabs(1.0 - 1.01)) << '\n';
    return 0;
}

How It Works

  1. The difference between two numbers is fabs(a - b). The numbers are "close" when the tolerance is greater than or equal to that difference.
  2. 0.1 + 0.2 is 0.30000000000000004, so the exact test == fails. The difference is about 5.5e-17, far below 0.001, so the close test passes.
  3. 1.0 and 1.0004 differ by 0.0004, which is within the tolerance. 1.0 and 1.01 differ by 0.01, which is too much.

Frequently Asked Questions

std::isgreaterequal(x, y) returns true if x is greater than or equal to y. It works like x >= y, but is quiet with NaN and returns false if either value is NaN.
true if x >= y, otherwise false. If either argument is NaN, the result is false.
isgreater() is false for equal numbers, and isgreaterequal() is true for equal numbers. Both are false when a NaN is involved.
It is safer to use a tolerance, for example fabs(a - b) <= 0.001. Small errors in decimal storage mean two values that look equal may differ in the last digit.
Include <cmath> and write std::isgreaterequal(). That always works and picks the C++ overloads. The global name ::isgreaterequal often works too, but the standard does not promise it, and it may only take a double.

Next: isinf()

Keep going through the <cmath> functions. Checks if a number is positive or negative infinity.

isinf() tutorial →

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.

11 people found this page helpful