From 934bed3d5ee17c00a8579d99bf7a5d5a9c81cc92 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Mon, 17 Nov 2025 07:47:29 -0500 Subject: [PATCH 01/12] Add islessgreater() term entry for C++ math-functions Added documentation for the islessgreater() function including: - Description and syntax - Example usage - Codebyte example with edge cases Fixes #7996 --- .../terms/islessgreater/islessgreater.md | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md new file mode 100644 index 00000000000..92b625505c3 --- /dev/null +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -0,0 +1,86 @@ +--- +Title: 'islessgreater()' +Description: 'Determines whether a floating-point value is less than or greater than another without setting floating-point exceptions.' +Subjects: + - 'Computer Science' +Tags: + - 'Functions' + - 'Arithmetic' +CatalogContent: + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +The **`islessgreater()`** function determines whether a floating-point value is less than or greater than another floating-point value. Unlike the built-in comparison operators (`<` and `>`), this function does not raise `FE_INVALID` exceptions when the arguments are `NaN`. + +## Syntax + +```pseudo +islessgreater(x, y) +``` + +The function takes two parameters: + +- `x`: A floating-point or integer value to compare. +- `y`: A floating-point or integer value to compare. + +The return value is `true` if `x` is less than or greater than `y` (i.e., `x < y || x > y`). Otherwise, `false` is returned. + +> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. + +## Example + +In the example below, the `islessgreater()` function compares two floating-point values: + +```cpp +#include +#include +using namespace std; + +int main() { + double x = 5.0; + double y = 10.0; + + cout << "islessgreater(5.0, 10.0): " << islessgreater(x, y) << "\n"; + cout << "islessgreater(10.0, 5.0): " << islessgreater(y, x) << "\n"; + cout << "islessgreater(5.0, 5.0): " << islessgreater(x, x) << "\n"; + + return 0; +} +``` + +This produces the following output: + +``` +islessgreater(5.0, 10.0): 1 +islessgreater(10.0, 5.0): 1 +islessgreater(5.0, 5.0): 0 +``` + +## Codebyte Example + +The example below demonstrates the `islessgreater()` function with different data types and edge cases, including `NaN` values: + +```codebyte/cpp +#include +#include +using namespace std; + +int main() { + float f1 = 3.14; + float f2 = 2.71; + double d1 = 100.0; + double d2 = 100.0; + long double ld1 = 1.5L; + long double ld2 = 2.5L; + + // NaN comparison + double nan_val = 0.0 / 0.0; + double normal_val = 5.0; + + cout << "islessgreater(3.14, 2.71): " << islessgreater(f1, f2) << "\n"; + cout << "islessgreater(100.0, 100.0): " << islessgreater(d1, d2) << "\n"; + cout << "islessgreater(1.5L, 2.5L): " << islessgreater(ld1, ld2) << "\n"; + cout << "islessgreater(NaN, 5.0): " << islessgreater(nan_val, normal_val) << "\n"; +} +``` From 26696dec520d0592e1f11dd93d1e13e0c46aed56 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Mon, 17 Nov 2025 07:52:06 -0500 Subject: [PATCH 02/12] Fix Prettier formatting - shorten description line Updated description to meet line length requirements for Prettier formatting check. --- .../terms/islessgreater/islessgreater.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 92b625505c3..4647979a433 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -1,6 +1,6 @@ --- Title: 'islessgreater()' -Description: 'Determines whether a floating-point value is less than or greater than another without setting floating-point exceptions.' +Description: 'Determines if a value is less than or greater than another.' Subjects: - 'Computer Science' Tags: @@ -40,11 +40,11 @@ using namespace std; int main() { double x = 5.0; double y = 10.0; - + cout << "islessgreater(5.0, 10.0): " << islessgreater(x, y) << "\n"; cout << "islessgreater(10.0, 5.0): " << islessgreater(y, x) << "\n"; cout << "islessgreater(5.0, 5.0): " << islessgreater(x, x) << "\n"; - + return 0; } ``` @@ -73,11 +73,11 @@ int main() { double d2 = 100.0; long double ld1 = 1.5L; long double ld2 = 2.5L; - + // NaN comparison double nan_val = 0.0 / 0.0; double normal_val = 5.0; - + cout << "islessgreater(3.14, 2.71): " << islessgreater(f1, f2) << "\n"; cout << "islessgreater(100.0, 100.0): " << islessgreater(d1, d2) << "\n"; cout << "islessgreater(1.5L, 2.5L): " << islessgreater(ld1, ld2) << "\n"; From ed3ad957f15788da8d6796e14631f107889d20e1 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:18:09 -0500 Subject: [PATCH 03/12] Apply review feedback: add Return value heading, improve description, use shell block --- .../math-functions/terms/islessgreater/islessgreater.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 4647979a433..3cfee5b19a9 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -24,7 +24,9 @@ The function takes two parameters: - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. -The return value is `true` if `x` is less than or greater than `y` (i.e., `x < y || x > y`). Otherwise, `false` is returned. +**Return value:** + +The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. > **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. @@ -51,7 +53,7 @@ int main() { This produces the following output: -``` +```shell islessgreater(5.0, 10.0): 1 islessgreater(10.0, 5.0): 1 islessgreater(5.0, 5.0): 0 From 13680e3c242651e9edba27999aac89ab7e036288 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:21:47 -0500 Subject: [PATCH 04/12] Fix Return value heading placement to line 26 From 342207b697919546ee761c5cbaee3e038857f99d Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:23:08 -0500 Subject: [PATCH 05/12] Remove blank line before Return value heading --- .../concepts/math-functions/terms/islessgreater/islessgreater.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 3cfee5b19a9..a835c94fd9f 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -23,7 +23,6 @@ The function takes two parameters: - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. - **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. From 038cea13abf1c801cae1733aeaa221a07de64fd7 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:28:12 -0500 Subject: [PATCH 06/12] Match repo formatting style with Parameters heading --- .../math-functions/terms/islessgreater/islessgreater.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index a835c94fd9f..7a45f3d8987 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -19,16 +19,17 @@ The **`islessgreater()`** function determines whether a floating-point value is islessgreater(x, y) ``` -The function takes two parameters: +**Parameters:** - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. + +> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. + **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. -> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. - ## Example In the example below, the `islessgreater()` function compares two floating-point values: From 37a542f350c9f36a1a9c19fdcd160bb71e9273f5 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:36:32 -0500 Subject: [PATCH 07/12] Move Note after Return value to place heading on line 26 --- .../math-functions/terms/islessgreater/islessgreater.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 7a45f3d8987..716da9a6426 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -24,12 +24,12 @@ islessgreater(x, y) - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. -> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. - **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. +> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. + ## Example In the example below, the `islessgreater()` function compares two floating-point values: From 780315c5d7719bc14902e37c3d28344152873ecc Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:37:38 -0500 Subject: [PATCH 08/12] Remove blank line to place Return value on line 26 --- .../concepts/math-functions/terms/islessgreater/islessgreater.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 716da9a6426..a237cb1c9c8 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -23,7 +23,6 @@ islessgreater(x, y) - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. - **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. From 38e3debf0aa16bd2bf57f1f38a21f21801bf92c9 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:39:28 -0500 Subject: [PATCH 09/12] Restore blank line before Return value for format compliance --- .../math-functions/terms/islessgreater/islessgreater.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index a237cb1c9c8..7a45f3d8987 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -23,12 +23,13 @@ islessgreater(x, y) - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. + +> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. + **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. -> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. - ## Example In the example below, the `islessgreater()` function compares two floating-point values: From d51910f5084afad7c21df6ae91902e0520146786 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:41:30 -0500 Subject: [PATCH 10/12] Remove blank line after syntax to place Return value on line 26 --- .../concepts/math-functions/terms/islessgreater/islessgreater.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 7a45f3d8987..2e942f0d0ae 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -18,7 +18,6 @@ The **`islessgreater()`** function determines whether a floating-point value is ```pseudo islessgreater(x, y) ``` - **Parameters:** - `x`: A floating-point or integer value to compare. From aadb56164e2d91d0d701007cd9e8a25d11c72f9e Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:43:24 -0500 Subject: [PATCH 11/12] Move Note after Return value to place heading on line 26 --- .../math-functions/terms/islessgreater/islessgreater.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 2e942f0d0ae..6128ab3aeae 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -23,12 +23,12 @@ islessgreater(x, y) - `x`: A floating-point or integer value to compare. - `y`: A floating-point or integer value to compare. -> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. - **Return value:** The function returns `true` if the two values are unequal and one is strictly less than or strictly greater than the other. It returns `false` when the values are equal or when either argument is `NaN`. +> **Note:** This function is particularly useful when working with floating-point values that might be `NaN`, as it provides a "quiet" comparison that won't trigger floating-point exceptions. + ## Example In the example below, the `islessgreater()` function compares two floating-point values: From 5ec1a9c6ecf0083919bcf50e0783c7686ab91b10 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Thu, 20 Nov 2025 09:46:06 -0500 Subject: [PATCH 12/12] Restore required blank line after syntax block for lint compliance --- .../concepts/math-functions/terms/islessgreater/islessgreater.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md index 6128ab3aeae..716da9a6426 100644 --- a/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md +++ b/content/cpp/concepts/math-functions/terms/islessgreater/islessgreater.md @@ -18,6 +18,7 @@ The **`islessgreater()`** function determines whether a floating-point value is ```pseudo islessgreater(x, y) ``` + **Parameters:** - `x`: A floating-point or integer value to compare.