C++ Math islessgreater()

Last Updated : 18 May 2026

Math islessgreater() Function

In C++, the islessgreater() function is defined in the <cmath> or <math.h> header file and is used to determine whether the first argument is either less than or greater than the second argument. In other words, it checks whether the two values are unequal. If the values are unequal, the function returns 1; otherwise, it returns 0.

The islessgreater() function supports float, double, long double, and other arithmetic data types.

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

Syntax

It has the following syntax.

Parameters

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

Return value

ParameterReturn value
x>y or x1
x=y or x=nan or y=nan0

Examples of islessgreater() Function

Here, we are going to discuss several examples to demonstrate the islessgreater() Function.

Example 1: Compare Two Equal Floating-Point Values Using islessgreater()

This example demonstrates how the islessgreater() function behaves when both values are equal.

Output:

Values of x and y are : 1.2,1.2
islessgreater(x,y) : 0

Explanation:

In this example, the values of both x and y are equal. Therefore, the function returns 0.

Example 2: Compare Two Unequal Values Using islessgreater()

This example demonstrates how the islessgreater() function behaves when the values are unequal and of different data types.

Output:

Values of x and y are : 7,3.2
islessgreater(x,y) : 1

Explanation:

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

Example 3: Compare a NaN Value Using islessgreater()

This example demonstrates how the islessgreater() function behaves when one of the values is NaN (Not a Number).

Output:

Values of x and y are : nan,3.2
islessgreater(x,y) : 0

Explanation:

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