C++ Math islessequal
The islessequal function verifies if the value of the initial argument is less than or equal to the second argument. It returns 1 if the value of the first argument is less than or equal to the value of the second argument; otherwise, it returns 0.
Note: If one or both the arguments are NAN then the function returns false(0).
Syntax
Consider two variables 'x' and 'y'. The syntax should be as follows:
bool islessequal(float x,float y);
bool islessequal(double x,double y);
bool islessequal(long double x,long double y);
bool islessequal(Arithmetic x,Arithmetic y);
Parameter
(x,y) : The values which we want to compare.
Return value
| Parameter(x,y) | Return value |
|---|---|
| x_PRESERVE7__y or x=nan or y=nan | 0 |
Example 1
Let's consider 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= 3.4;
float y=3.4;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessequal(x,y) : "<<islessequal(x,y);
return 0;
}
Output:
Values of x and y are : 3.4,3.4
islessequal(x,y) : 1
In this instance, the islessequal function establishes that x and y are equal, resulting in a return value of 1.
Example 2
Let's examine a basic scenario where both variables x and y are of distinct data types.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 7.8;
int y=2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessequal(x,y) : "<<islessequal(x,y);
return 0;
}
Output:
Values of x and y are : 7.8,2
islessequal(x,y) : 0
In this instance, the value of x surpasses y. As a result, the function will output 0.
Example 2
Let's see a simple example .
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 0.0/0.0;
float y=0.0/0.0;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"islessequal(x,y) : "<<islessequal(x,y);
return 0;
}
Output:
Values of x and y are : nan,nan
islessequal(x,y) : 0
In this instance, both x and y are NaN. As a result, the function will output a value of 0.