File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
inst/include/Rcpp/internal Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,31 @@ struct NAComparator<double> {
7272
7373};
7474
75+ template <>
76+ struct NAComparator <Rcomplex> {
77+ inline bool operator ()(Rcomplex left, Rcomplex right) const {
78+ // sort() in R says that complex numbers are first sorted by
79+ // the real parts, and then the imaginary parts.
80+
81+ // When only one of the two numbers contains NA or NaN, move
82+ // it to the right hand side.
83+
84+ // When both left and right contain NA or NaN, return true.
85+
86+ bool leftNaN = (left.r != left.r ) || (left.i != left.i );
87+ bool rightNaN = (right.r != right.r ) || (right.i != right.i );
88+
89+ if (!(leftNaN || rightNaN)) // if both are nice numbers
90+ {
91+ if (left.r == right.r ) // if real parts are the same
92+ return left.i < right.i ;
93+ else
94+ return left.r < right.r ;
95+ } else
96+ return leftNaN <= rightNaN;
97+ }
98+ };
99+
75100template <>
76101struct NAComparator <SEXP> {
77102 inline bool operator ()(SEXP left, SEXP right) const {
You can’t perform that action at this time.
0 commit comments