The islessgreater function checks if the value of the first parameter is either less than or greater than the value of the second parameter. It will return 1 if the first parameter is less than or greater than the second parameter; otherwise, it will return 0.
Note: If one or both the arguments are NAN, then the function returns false(0).
Syntax
Consider a pair of numerical values denoted as 'x' and 'y'. The syntax is as follows:
bool islessgreater(float x, float y);
bool islessgreater(double x, double y);
bool islessgreater(long double x, long double y);
bool islessgreater(Arithmetic x, Arithmetic y);
Parameter
(x,y) : The values which we want to compare.
Return value
| Parameter | Return value |
|---|---|
| x>y or x | 1 |
| x=y or x=nan or y=nan | 0 |
Example 1
Let's examine a basic scenario where both variables x and y hold the same value.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=1.2;
float y=1.2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessgreater(x,y) : "<<islessgreater(x,y);
return 0;
}
Output:
Values of x and y are : 1.2,1.2
islessgreater(x,y) : 0
In this instance, the values of x and y are identical. As a result, the function will output 0.
Example 2
Let's consider a basic scenario where both variables x and y are of distinct data types and have different values.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=7;
float y=3.2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessgreater(x,y) : "<<islessgreater(x,y);
return 0;
}
Output:
Values of x and y are : 7,3.2
islessgreater(x,y) : 1
In this instance, the value assigned to x surpasses the value assigned to y. As a result, the function yields a return value of 1.
Example 3
Let's consider a basic scenario where the value of x is NaN.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=0.0/0.0;
float y=3.2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessgreater(x,y) : "<<islessgreater(x,y);
return 0;
}
Output:
Values of x and y are : nan,3.2
islessgreater(x,y) : 0
In this instance, the value of x is not a number (NAN). As a result, the function will output 0.