comparison liboctave/Array-fC.cc @ 8725:d5af326a3ede

[mq]: sort-traits
author John W. Eaton <jwe@octave.org>
date Thu, 12 Feb 2009 02:49:14 -0500
parents e9cb742df9eb
children 06b9903a029b
comparison
equal deleted inserted replaced
8724:a50228129dba 8725:d5af326a3ede
33 #include "Array.h" 33 #include "Array.h"
34 #include "Array.cc" 34 #include "Array.cc"
35 #include "oct-sort.cc" 35 #include "oct-sort.cc"
36 36
37 template <> 37 template <>
38 inline bool _sort_isnan (FloatComplex x) 38 inline bool
39 sort_isnan<FloatComplex> (const FloatComplex& x)
39 { 40 {
40 return xisnan (x); 41 return xisnan (x);
41 } 42 }
42 43
43 template <> 44 template <>
44 bool 45 bool
45 octave_sort<FloatComplex>::ascending_compare (FloatComplex a, FloatComplex b) 46 octave_sort<FloatComplex>::ascending_compare (const FloatComplex& a,
47 const FloatComplex& b)
46 { 48 {
47 return ((std::abs (a) < std::abs (b)) 49 return ((std::abs (a) < std::abs (b))
48 || ((std::abs (a) == std::abs (b)) && (arg (a) < arg (b)))); 50 || ((std::abs (a) == std::abs (b)) && (arg (a) < arg (b))));
49 } 51 }
50 52
51 template <> 53 template <>
52 bool 54 bool
53 octave_sort<FloatComplex>::descending_compare (FloatComplex a, FloatComplex b) 55 octave_sort<FloatComplex>::descending_compare (const FloatComplex& a,
56 const FloatComplex& b)
54 { 57 {
55 return ((std::abs (a) > std::abs (b)) 58 return ((std::abs (a) > std::abs (b))
56 || ((std::abs (a) == std::abs (b)) && (arg (a) > arg (b)))); 59 || ((std::abs (a) == std::abs (b)) && (arg (a) > arg (b))));
57 } 60 }
58 61
59 static bool nan_ascending_compare (FloatComplex x, FloatComplex y) 62 static bool
63 nan_ascending_compare (const FloatComplex& x, const FloatComplex& y)
60 { 64 {
61 return xisnan (y) ? ! xisnan (x) : ((std::abs (x) < std::abs (x)) 65 return (xisnan (y)
62 || ((std::abs (x) == std::abs (x)) && (arg (x) < arg (x)))); 66 ? ! xisnan (x)
67 : ((std::abs (x) < std::abs (x))
68 || ((std::abs (x) == std::abs (x)) && (arg (x) < arg (x)))));
63 } 69 }
64 70
65 static bool nan_descending_compare (FloatComplex x, FloatComplex y) 71 static bool
72 nan_descending_compare (const FloatComplex& x, const FloatComplex& y)
66 { 73 {
67 return xisnan (x) ? ! xisnan (y) : ((std::abs (x) > std::abs (x)) 74 return (xisnan (x)
68 || ((std::abs (x) == std::abs (x)) && (arg (x) > arg (x)))); 75 ? ! xisnan (y)
76 : ((std::abs (x) > std::abs (x))
77 || ((std::abs (x) == std::abs (x)) && (arg (x) > arg (x)))));
69 } 78 }
70 79
71 bool (*_sortrows_comparator (sortmode mode, 80 Array<FloatComplex>::compare_fcn_type
72 const Array<FloatComplex>& a , bool allow_chk)) 81 sortrows_comparator (sortmode mode, const Array<FloatComplex>& a,
73 (FloatComplex, FloatComplex) 82 bool allow_chk)
74 { 83 {
75 bool (*result) (FloatComplex, FloatComplex) = 0; 84 Array<FloatComplex>::compare_fcn_type result = 0;
76 85
77 if (allow_chk) 86 if (allow_chk)
78 { 87 {
79 octave_idx_type k = 0; 88 octave_idx_type k = 0;
80 for (; k < a.numel () && ! xisnan (a(k)); k++) ; 89 for (; k < a.numel () && ! xisnan (a(k)); k++) ;