Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
Title: 'isgreaterequal()'
Description: 'Determines whether the first floating-point value is greater than or equal to the second, without raising floating-point exceptions.'
Subjects:
- 'Computer Science'
- 'Game Development'
Tags:
- 'Functions'
- 'Math'
CatalogContent:
- 'learn-c-plus-plus'
- 'paths/computer-science'
---

The **`isgreaterequal()`** [function](https://www.codecademy.com/resources/docs/cpp/functions) 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

```pseudo
isgreaterequal(x, y)
```

**Parameters:**

- `x`, `y`: Floating-point or integers types.

> **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 raise `FE_INVALID` if one or both of the arguments is `NaN`. The function `isgreaterequal()` is a "quiet" version of operator `>=`.

**Return value:**

The `isgreaterequal()` 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`:

```cpp
#include <iostream>
#include <cmath>

using namespace std;

int main() {
float x = 5.5;
int y = 3;
double z = nan("1");

cout << boolalpha;
cout << x << " isgreaterequal to " << y << ": " << isgreaterequal(x, y) << endl;
cout << y << " isgreaterequal to " << x << ": " << isgreaterequal(y, x) << endl;
cout << x << " isgreaterequal to " << z << ": " << isgreaterequal(x, z) << " (NaN comparison)" << endl;

return 0;
}
```

The output of this code is as follows:

```shell
5.5 isgreaterequal to 3: true
3 isgreaterequal to 5.5: false
5.5 isgreaterequal 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()`:

```codebyte/cpp
#include <iostream>
#include <cmath>
using namespace std;

int main() {
float a = 2.5;
float b = 7.3;

cout << boolalpha;
cout << a << " isgreaterequal to " << b << ": " << isgreaterequal(a, b) << endl;
cout << b << " isgreaterequal to " << a << ": " << isgreaterequal(b, a) << endl;

return 0;
}
```