C++ Math less
The less function checks if the value of the first argument is smaller than the value of the second argument. It returns 1 if the first argument is indeed less than the second, 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 is as follows:
bool less(float x, float y);
bool less(double x, double y);
bool less(long double x, long double y);
bool less(Arithmetic x, Arithmetic y);
Parameter
(x,y) : The values which we want to compare.
Return value
| Parameter(x,y) | Return value |
|---|---|
x |
1 |
| x>y or x=nan or y=nan | 0 |
Example 1
Let's consider a straightforward scenario where both variables x and y are of the same data type.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=1.2;
float y=1.3;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isless(x,y) : "<<isless(x,y);
return 0;
}
Output:
Values of x and y are : 1.2,1.3
isless(x,y) : 1
In this instance, the isless function evaluates whether the value of x is lower than y, 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.2;
int y=5;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isless(x,y) : "<<isless(x,y);
return 0;
}
Output:
Values of x and y are : 7.2,5
isless(x,y) :0
In this instance, the isless function establishes that the value of x is not smaller than y, resulting in a return value of 0.
Example 3
Let's examine a basic scenario where the x variable equals NaN.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= 0.0/0.0;
float y=5.67;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isless(x,y) : "<<isless(x,y);
return 0;
}
Output:
Values of x and y are : nan,5.67
isless(x,y) : 0
In this instance, the value of x is NaN. As a result, the function will yield a return value of 0.