C++ islessequal()

MamtaWardhani's avatar
Published Jan 25, 2026
Contribute to Docs

The islessequal() function compares two floating-point values and returns true if the first value is less than or equal to the second. It performs a quiet comparison, meaning it does not raise floating-point exceptions and always returns false if either value is NaN.

This function is provided by the <cmath> header and is safer than using the <= operator when working with floating-point edge cases.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Syntax

islessequal(x, y)

Parameters:

  • x: The first numeric value to compare.
  • y: The second numeric value to compare. Both parameters can be floating-point or integer types due to overloads.

Return value:

  • Returns true if x is less than or equal to y and neither value is NaN.
  • Returns false otherwise, including when either argument is NaN.

Example 1: Comparing two numeric values

In this example, islessequal() is used to compare two regular numeric values:

#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a = 4.5;
double b = 7.2;
cout << boolalpha;
cout << islessequal(a, b) << endl;
cout << islessequal(b, a) << endl;
return 0;
}

The output of this code is:

true
false

Example 2: Comparison involving NaN

In this example, islessequal() safely handles a comparison involving NaN:

#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x = 5.0;
double y = NAN;
cout << boolalpha;
cout << islessequal(x, y) << endl;
cout << islessequal(y, x) << endl;
return 0;
}

The output of this code is:

false
false

Codebyte Example

In this example, islessequal() is used inside a helper function to check ordering between different numeric inputs:

Code
Output

Frequently Asked Questions

1. What is the equal function in C++?

C++ does not have a standalone equal() function for basic comparisons; equality is typically checked using the == operator, or with helper functions like std::equal() for ranges.

2. What is the math library function in C++?

C++ math functions such as sqrt(), pow(), sin(), and islessequal() are provided by the <cmath> header.

3. Should I use equals() or == for string compare?

In C++, strings should be compared using == when working with std::string. The equals() method does not exist in standard C++.

All contributors

Contribute to Docs

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours