C++ Standard Library C++ STL Library

C++ <cmath> - islessgreater() Function



The C++ <cmath> islessgreater() function returns true if the first argument is less than or greater than the second argument, else returns false. If any of the arguments is NaN, the function returns false, and no FE_INVALID exception is raised but using (x<y||x>y) may raise such exception.

Syntax

bool islessgreater (float x, float y);
bool islessgreater (double x, double y);
bool islessgreater (long double x, long double y);                  

Parameters

x Specify first value to be compared.
y Specify second value to be compared.

Return Value

Returns true (1) if the first argument is less than or greater than the second argument, else returns false (0).

Example:

The example below shows the usage of islessgreater() function.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  int x = 10;
  int y = 50;
  int z = 10;

  cout<<boolalpha;
  cout<<"(x < y OR x > y): "<<islessgreater(x, y);
  cout<<endl;
  cout<<"(x < z OR x > z): "<<islessgreater(x, z);
  cout<<endl;
  cout<<"(y < z OR y > z): "<<islessgreater(y, z);

  return 0;
}

The output of the above code will be:

(x < y OR x > y): true
(x < z OR x > z): false
(y < z OR y > z): true

❮ C++ <cmath> Library