C++ isgreater()
Anonymous contributor
Published Nov 19, 2025
Contribute to Docs
The isgreater() function compares two floating-point values and returns true only when the first is strictly greater than the second. It follows IEEE-754 rules, never raises floating-point exceptions, and always returns false if either argument is NaN. Integer inputs are promoted to floating-point. The function is available through the <cmath> header.
Syntax
isgreater(x, y)
Parameters:
x,y: Arithmetic values (integers or floating-point types).
Note: Integer arguments are promoted to the appropriate floating-point type.
Return value:
The isgreater() 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 <iostream>#include <cmath>using namespace std;int main() {double x = 10.5;double y = 5.2;double z = nan("1");cout << boolalpha;cout << "isgreater(x, y): " << isgreater(x, y) << endl;cout << "isgreater(x, z): " << isgreater(x, z) << " (NaN comparison)" << endl;return 0;}
The output of this code is as follows:
isgreater(x, y): trueisgreater(x, z): false (NaN comparison)
Codebyte Example
The following example is runnable and outputs whether one number is greater than another using isgreater():
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
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