Skip to content

Commit 0182d60

Browse files
Add isgreater() documentation entry for C++ (#7998)
* Create isgreater.md * Create isgreater.md * Delete content/cpp/concepts/math-functions directory * minor content fixes * Update isgreater.md * Update isgreater.md * Update isgreater.md ---------
1 parent e5e5d35 commit 0182d60

File tree

1 file changed

+88
-0
lines changed
  • content/cpp/concepts/math-functions/terms/isgreater

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
Title: 'isgreater()'
3+
Description: 'Compares two floating-point values and returns true if the first is strictly greater than the second.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
- 'Game Development'
8+
Tags:
9+
- 'Functions'
10+
- 'Comparison'
11+
- 'Math'
12+
CatalogContent:
13+
- 'learn-c-plus-plus'
14+
- 'paths/computer-science'
15+
---
16+
17+
The **`isgreater()`** [function](https://www.codecademy.com/resources/docs/cpp/functions) 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.
18+
19+
## Syntax
20+
21+
```pseudo
22+
isgreater(x, y)
23+
```
24+
25+
**Parameters:**
26+
27+
- `x`, `y`: Arithmetic values (integers or floating-point types).
28+
29+
> **Note:** Integer arguments are promoted to the appropriate floating-point type.
30+
31+
**Return value:**
32+
33+
The `isgreater()` function returns:
34+
35+
- `true` if `x > y` and neither argument is `NaN`
36+
- `false` otherwise, including when either value is `NaN`
37+
38+
## Example
39+
40+
The following example checks whether one number is greater than another, including a comparison involving `NaN`:
41+
42+
```cpp
43+
#include <iostream>
44+
#include <iostream>
45+
#include <cmath>
46+
47+
using namespace std;
48+
49+
int main() {
50+
double x = 10.5;
51+
double y = 5.2;
52+
double z = nan("1");
53+
54+
cout << boolalpha;
55+
cout << "isgreater(x, y): " << isgreater(x, y) << endl;
56+
cout << "isgreater(x, z): " << isgreater(x, z) << " (NaN comparison)" << endl;
57+
58+
return 0;
59+
}
60+
```
61+
62+
The output of this code is as follows:
63+
64+
```shell
65+
isgreater(x, y): true
66+
isgreater(x, z): false (NaN comparison)
67+
```
68+
69+
## Codebyte Example
70+
71+
The following example is runnable and outputs whether one number is greater than another using `isgreater()`:
72+
73+
```codebyte/cpp
74+
#include <iostream>
75+
#include <cmath>
76+
using namespace std;
77+
78+
int main() {
79+
double a = 7.5;
80+
double b = 9.3;
81+
82+
cout << boolalpha;
83+
cout << "isgreater(a, b): " << isgreater(a, b) << endl;
84+
cout << "isgreater(b, a): " << isgreater(b, a) << endl;
85+
86+
return 0;
87+
}
88+
```

0 commit comments

Comments
 (0)