C++ isgreaterequal()
Anonymous contributor
Published Feb 19, 2026
The isgreaterequal() function compares two arithmetic values and returns true only when the first is greater than or equal to the second. It never raises floating-point exceptions and always returns false if either argument is NaN. The function is available through the <cmath> header.
Syntax
isgreaterequal(x, y)
Parameters:
x,y: Floating-point or integer values.
Notes:
- The function
isgreaterequal()is defined with overloads so it works with any mix of arithmetic values.- The built-in operator
>=for floating-point numbers may raiseFE_INVALIDif one or both of the arguments isNaN. The functionisgreaterequal()is a “quiet” version of operator>=.
Return value:
The isgreaterequal() function returns:
trueifx >= yand neither argument isNaNfalseotherwise, including when either value isNaN
Example
The following example checks whether one number is greater than another, including a comparison involving NaN:
#include <iostream>#include <cmath>using namespace std;int main() {float x = 5.5;int y = 3;double z = nan("1");cout << boolalpha;cout << x << " is greater than or equal to " << y << ": " << isgreaterequal(x, y) << endl;cout << y << " is greater than or equal to " << x << ": " << isgreaterequal(y, x) << endl;cout << x << " is greater than or equal to " << z << ": " << isgreaterequal(x, z) << " (NaN comparison)" << endl;return 0;}
The output for this code is as follows:
5.5 is greater than or equal to 3: true3 is greater than or equal to 5.5: false5.5 is greater than or equal to nan: false (NaN comparison)
Codebyte Example
The following example is runnable and outputs whether one number is greater than or equal to another using isgreaterequal():
All contributors
- Anonymous contributor
Learn C++ on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
- Beginner Friendly.11 hours