Math Less Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Less Function

Math Less Function

BLUF: Mastering Math Less Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Less Function

C++ is renowned for its efficiency. Learn how Math Less Function enables low-level control and high-performance computing in the tutorial below.

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:

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 consider a straightforward scenario where both variables x and y are of the same data 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 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.

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 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.

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 instance, the value of x is NaN. As a result, the function will yield a return value of 0.

Input Required

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

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience