Math Isgreater Function

C++ Math isgreater

The isgreater function determines whether the value of first argument given in function is greater than the value of second argument. If the first number is greater, it returns 1 otherwise 0.

Note: If one or both the arguments of a function are NAN then it returns 0.

Syntax

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

Example

bool isgreater(float x, float y);
bool isgreater(double x, double y);
bool isgreater(long double x, long double y);
bool isgreater(Arithmetic x, Arithmetic y);

Note: The arithmetic type can be of any type. It can be either float, double, long double, int or char. If any parameter is integer type, then it is cast to double.

Parameter

x,y : The values which we want to compare.

Return value

Parameter(x,y) Return value
x>y 1
x 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=9.0;
  float y=7.0;
  cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
  cout<<"isgreater(x,y) : "<<isgreater(x,y);
  return 0;
}

Output:

Output

Values of x and y are : 9.0,7.0
isgreater(x,y) : 1

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

Example 2

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

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  double x=45.4;
  char y='c';
  cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
  cout<<"isgreater(x,y) : "<<isgreater(x,y);
  return 0;
}

Output:

Output

Values of x and y are : 45.4,c
isgreater(x,y) : 0

In this example, isgreater function determines that the value of x is less than y as the ASCII value of 'c' is greater than the value of x. Therefore, it returns 0.

Example 3

Let's see a simple example when x is equal to NAN.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  double x=0.0/0.0;
  double y=12.3;
  cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
  cout<<"isgreater(x,y) : "<<isgreater(x,y);
  return 0;
}

Output:

Output

Values of x and y are : nan , 12.3
isgreater(x,y) : 0

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

Input Required

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