C++ Math isgreater
The isgreater function checks if the value of the first parameter provided is higher than the value of the second parameter. It will output 1 if the first number is indeed greater, otherwise it will return 0.
Note: If one or both the arguments of a function are NAN then it returns 0.
Syntax
Consider a pair of numerical values denoted as 'x' and 'y'. The syntax for this representation is as follows:
bool isgreater(float x, float y);
bool isgreater(double x, double y);
bool isgreater(long double x, long double y);
bool isgreater(Arithmetic x, Arithmetic y);
Note: The arithmetic type can be of any type. It can be either float, double, long double, int or char. If any parameter is integer type, then it is cast to double.
Parameter
x,y : The values which we want to compare.
Return value
| Parameter(x,y) | Return value |
|---|---|
x>y |
1 |
x |
0 |
Example 1
Let's examine a straightforward scenario where both variables x and y are of identical data type.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=9.0;
float y=7.0;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isgreater(x,y) : "<<isgreater(x,y);
return 0;
}
Output:
Values of x and y are : 9.0,7.0
isgreater(x,y) : 1
In this instance, the isgreater function assesses that the value of x exceeds y, resulting in a return value of 1.
Example 2
Let's consider a basic scenario where both variables x and y are of distinct data types.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=45.4;
char y='c';
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isgreater(x,y) : "<<isgreater(x,y);
return 0;
}
Output:
Values of x and y are : 45.4,c
isgreater(x,y) : 0
In this instance, the isgreater function establishes that the value of x is smaller than y due to the ASCII value of 'c' being higher than x. Consequently, it yields a result of 0.
Example 3
Let's consider a straightforward scenario where x is equal to NaN.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=0.0/0.0;
double y=12.3;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isgreater(x,y) : "<<isgreater(x,y);
return 0;
}
Output:
Values of x and y are : nan , 12.3
isgreater(x,y) : 0
In this scenario, the value of x is NaN. As a result, the function will output 0.