Math Less Function

C++ Math less

The less function determines whether the value of first argument is less than the value of second argument. If first argument is less than the second argument then it returns 1 otherwise 0.

Note: If one or both the arguments are NAN, then the function returns false(0).

Syntax

Consider two numbers 'x' and 'y'. Syntax would be:

Example

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 see a simple example when both x and y are of same type.

Example

#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:

Output

Values of x and y are : 1.2,1.3
isless(x,y) : 1

In this example, isless function determines that the value of x is less than y. Therefore, it returns 1.

Example 2

Let's see a simple example when both x and y are of different type.

Example

#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:

Output

Values of x and y are : 7.2,5
isless(x,y) :0

In this example, isless function determines that the value of x is not less than y. Therefore, it returns 0.

Example 3

Let's see a simple example when the value of x is nan.

Example

#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:

Output

Values of x and y are : nan,5.67
isless(x,y) : 0

In this example, value of x is nan. Therefore, the function returns 0.

Input Required

This code uses input(). Please provide values below: