-
Notifications
You must be signed in to change notification settings - Fork 30
Sort NaNs to the end for descending order #3066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
989538b
6872854
5210a9d
8383540
7e8cadf
a4079d4
ce73016
68af50f
e385256
808365e
490c858
f709514
20c89fc
0be0f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,9 +60,10 @@ struct ExtendedRealFPLess | |
| template <typename fpT> | ||
| struct ExtendedRealFPGreater | ||
| { | ||
| /* [R, nan] — NaNs sort to the end, as in ascending order */ | ||
| bool operator()(const fpT v1, const fpT v2) const | ||
| { | ||
| return (!std::isnan(v2) && (std::isnan(v1) || (v2 < v1))); | ||
| return (!std::isnan(v1) && (std::isnan(v2) || (v2 < v1))); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -106,10 +107,38 @@ struct ExtendedComplexFPLess | |
| template <typename cT> | ||
| struct ExtendedComplexFPGreater | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, done —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One perf note for the record: this form constructs two
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it's more readable and less code duplication, I think we should revert it. Potential performance issues and while negation preserves
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, I'd also vote for reverting if no other concern @vlad-perevezentsev |
||
| { | ||
| /* [(R, R), (R, nan), (nan, R), (nan, nan)] — NaN-containing values keep | ||
| the same trailing groups as ascending order; only the finite-component | ||
| comparison within a group is reversed */ | ||
| bool operator()(const cT &v1, const cT &v2) const | ||
| { | ||
| auto less_ = ExtendedComplexFPLess<cT>{}; | ||
| return less_(v2, v1); | ||
| using realT = typename cT::value_type; | ||
|
|
||
| const realT real1 = std::real(v1); | ||
| const realT real2 = std::real(v2); | ||
|
|
||
| const bool r1_nan = std::isnan(real1); | ||
| const bool r2_nan = std::isnan(real2); | ||
|
|
||
| const realT imag1 = std::imag(v1); | ||
| const realT imag2 = std::imag(v2); | ||
|
|
||
| const bool i1_nan = std::isnan(imag1); | ||
| const bool i2_nan = std::isnan(imag2); | ||
|
|
||
| const int idx1 = ((r1_nan) ? 2 : 0) + ((i1_nan) ? 1 : 0); | ||
| const int idx2 = ((r2_nan) ? 2 : 0) + ((i2_nan) ? 1 : 0); | ||
|
|
||
| const bool res = | ||
| !(r1_nan && i1_nan) && | ||
| ((idx1 < idx2) || | ||
| ((idx1 == idx2) && | ||
| ((r1_nan && !i1_nan && (imag2 < imag1)) || | ||
| (!r1_nan && i1_nan && (real2 < real1)) || | ||
| (!r1_nan && !i1_nan && | ||
| ((real2 < real1) || (!(real1 < real2) && (imag2 < imag1))))))); | ||
|
|
||
| return res; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.