Mercurial > hg > octave-nkf
annotate liboctave/array/Array-C.cc @ 19887:3db04b75c7c0
do not set text encoding for strings to utf-8 on windows (bug #44103)
* octave-gui.cc (octave_start_gui): only use setCodecForCStrings when not
building for windows
author | Torsten <ttl@justmail.de> |
---|---|
date | Mon, 09 Feb 2015 22:09:36 +0100 |
parents | bdf90710dddf |
children | 4197fc428c7d |
rev | line source |
---|---|
757 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
3 Copyright (C) 1994-2013 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10374
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
757 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
757 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
757 | 21 |
22 */ | |
23 | |
2006 | 24 #ifdef HAVE_CONFIG_H |
25 #include <config.h> | |
26 #endif | |
27 | |
757 | 28 // Instantiate Arrays of Complex values. |
29 | |
1989 | 30 #include "oct-cmplx.h" |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
31 #include "lo-mappers.h" |
1989 | 32 |
757 | 33 #include "Array.h" |
34 #include "Array.cc" | |
8700 | 35 #include "oct-sort.cc" |
7433 | 36 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
37 template <> |
8725 | 38 inline bool |
39 sort_isnan<Complex> (const Complex& x) | |
7433 | 40 { |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
41 return xisnan (x); |
7433 | 42 } |
43 | |
19832
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
44 // Sort Criteria: 1) isnan, 2) magnitude of z, 3) phase of z in range (-pi, pi] |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
45 |
8725 | 46 static bool |
47 nan_ascending_compare (const Complex& x, const Complex& y) | |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
48 { |
19832
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
49 if (xisnan (y)) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
50 return (! xisnan (x)); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
51 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
52 double xabs = std::abs (x); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
53 double yabs = std::abs (y); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
54 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
55 if (xabs < yabs) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
56 return true; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
57 else if (xabs == yabs) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
58 { |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
59 double xarg = arg (x); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
60 double yarg = arg (y); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
61 xarg = (xarg == -M_PI) ? M_PI : xarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
62 yarg = (yarg == -M_PI) ? M_PI : yarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
63 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
64 return xarg < yarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
65 } |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
66 else |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
67 return false; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
68 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
69 |
8725 | 70 static bool |
71 nan_descending_compare (const Complex& x, const Complex& y) | |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
72 { |
19832
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
73 if (xisnan (x)) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
74 return (! xisnan (y)); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
75 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
76 double xabs = std::abs (x); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
77 double yabs = std::abs (y); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
78 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
79 if (xabs > yabs) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
80 return true; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
81 else if (xabs == yabs) |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
82 { |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
83 double xarg = arg (x); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
84 double yarg = arg (y); |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
85 xarg = (xarg == -M_PI) ? M_PI : xarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
86 yarg = (yarg == -M_PI) ? M_PI : yarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
87 |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
88 return xarg > yarg; |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
89 } |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
90 else |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19830
diff
changeset
|
91 return false; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
92 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
93 |
8725 | 94 Array<Complex>::compare_fcn_type |
9920
56fbe170d354
fix issorted with NaNs in middle
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
95 safe_comparator (sortmode mode, const Array<Complex>& a , bool allow_chk) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
96 { |
8725 | 97 Array<Complex>::compare_fcn_type result = 0; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
98 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
99 if (allow_chk) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
100 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
101 octave_idx_type k = 0; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
102 for (; k < a.numel () && ! xisnan (a(k)); k++) ; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
103 if (k == a.numel ()) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
104 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
105 if (mode == ASCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
106 result = octave_sort<Complex>::ascending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
107 else if (mode == DESCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
108 result = octave_sort<Complex>::descending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
109 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
110 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
111 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
112 if (! result) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
113 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
114 if (mode == ASCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
115 result = nan_ascending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
116 else if (mode == DESCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
117 result = nan_descending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
118 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
119 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
120 return result; |
7433 | 121 } |
122 | |
19590
fb09907f4e49
Remove single line makro INSTANTIATE_ARRAY_SORT.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17769
diff
changeset
|
123 template class OCTAVE_API octave_sort<Complex>; |
757 | 124 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
125 INSTANTIATE_ARRAY (Complex, OCTAVE_API); |
3836 | 126 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 template OCTAVE_API std::ostream& operator << (std::ostream&, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
128 const Array<Complex>&); |
4513 | 129 |
1989 | 130 #include "DiagArray2.h" |
131 #include "DiagArray2.cc" | |
132 | |
6108 | 133 template class OCTAVE_API DiagArray2<Complex>; |