isgreaterequal() function with example in C++

C++ isgreaterequal() function: Here, we are going to learn about the isgreaterequal() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on May 17, 2020

C++ isgreaterequal() function

isgreaterequal() function is a library function of cmath header, it is used to check whether the given first value is greater than or equal to the second value. It accepts two values (float, double or long double) and returns 1 if the first value is greater than or equal to the second value; 0, otherwise.

Syntax of isgreaterequal() function:

In C99, it has been implemented as a macro,

    macro isgreaterequal(x, y)

In C++11, it has been implemented as a function,

    bool isgreaterequal (float x      , float y);
    bool isgreaterequal (double x     , double y);
    bool isgreaterequal (long double x, long double y);

Parameter(s):

  • x, y – represent the two values to be checked whether x is greater than or equal to the y.

Return value:

The returns type of this function is bool, it returns 1 if x is greater than or equal to y; 0, otherwise.

Example:

    Input:
    float x = 10.0f;
    float y = 5.0f;
    
    Function call:
    isgreaterequal(x, y);
    
    Output:
    1

C++ code to demonstrate the example of isgreaterequal() function

// C++ code to demonstrate the example of
// isgreaterequal() function

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    cout << "isgreaterequal(0.0f, -2.0f)   : " << isgreaterequal(0.0f, -2.0f) << endl;
    cout << "isgreaterequal(10.0f, 20.0f)  : " << isgreaterequal(10.0f, 20.0f) << endl;
    cout << "isgreaterequal(10.0f, 10.0f)  : " << isgreaterequal(10.0f, 10.0f) << endl;
    cout << "isgreaterequal(-10.0f, -20.0f): " << isgreaterequal(-10.0f, -20.0f) << endl;

    float x = 10.0f;
    float y = 5.0f;

    // checking using the condition
    if (isgreaterequal(x, y)) {
        cout << x << " is greater than or equal to " << y << endl;
    }
    else {
        cout << x << " is not greater than or equal to " << y << endl;
    }

    x = 10.0f;
    y = 10.0f;

    if (isgreaterequal(x, y)) {
        cout << x << " is greater than or equal to " << y << endl;
    }
    else {
        cout << x << " is not greater than or equal to " << y << endl;
    }

    return 0;
}

Output

isgreaterequal(0.0f, -2.0f)   : 1
isgreaterequal(10.0f, 20.0f)  : 0
isgreaterequal(10.0f, 10.0f)  : 1
isgreaterequal(-10.0f, -20.0f): 1
10 is greater than or equal to 5
10 is greater than or equal to 10

Reference: C++ isgreaterequal() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.