C++ isgreater()

Anonymous contributor's avatar
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.

  • 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

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:

  • true if x > y and neither argument is NaN
  • false otherwise, including when either value is NaN

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): true
isgreater(x, z): false (NaN comparison)

Codebyte Example

The following example is runnable and outputs whether one number is greater than another using isgreater():

Code
Output
Loading...

All contributors

Contribute to 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