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

Math Islessgreater Function

BLUF: Mastering Math Islessgreater 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 Islessgreater Function

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

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:

Example

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.

Example

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

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.

Example

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

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.

Example

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

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.

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