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
Call
What 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
Parameter
Description
x
Required. The first number to compare. It can be float, double, long double, or an integer type.
y
Required. The second number to compare.
Return Value
Return Value
Description
true
x is greater than or equal to y.
false
x 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;
}
Output
5 vs 3: true
4 vs 4: true
3 vs 5: false
0.5 vs 0.25: true
1 vs NaN: false
How It Works
The loop gives each pair to isgreaterequal() and prints the answer next to its label.
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 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.
0.1 + 0.2 vs 0.3: exact false, close true
1.0 vs 1.0004: close true
1.0 vs 1.01: close false
How It Works
The difference between two numbers is fabs(a - b). The numbers are "close" when the tolerance is greater than or equal to that difference.
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.
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.