annotate test/complex.tst @ 20132:31e3799b9e27

Map -pi to pi for principal argument in complex operators with float values (bug #43313) * Array-fC.cc (nan_ascending_compare, nan_descending_compare): Use static_cast to float on M_PI so that comparisons work. * oct-cmplx.h (DEF_COMPLEXR_COMP): Use static_cast to type <T> on M_PI so that comparisons work. * complex.tst: Add tests for single values on top of those for double.
author Rik <rik@octave.org>
date Tue, 10 Mar 2015 09:42:19 -0700
parents bdf90710dddf
children 117ccb5080c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
1 ## Copyright (C) 2015 Rik Wehbring
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
2 ##
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
3 ## This file is part of Octave.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
4 ##
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
8 ## your option) any later version.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
9 ##
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
13 ## General Public License for more details.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
14 ##
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
18
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
19 ## Test ordering of complex values by magnitude and then by phase
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
20 %!test
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
21 %! x = [0 i 1+i 2 3i 3+4i];
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
22 %! assert (sort (x, "descend"), fliplr (x));
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
23 %! assert (sort (single (x), "descend"), fliplr (single (x)));
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
24
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
25 %!test
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
26 %! x = [1, -1, i, -i];
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
27 %! xs = [-i, 1, i, -1];
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
28 %! assert (sort (x), xs);
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
29 %! assert (sort (x, "descend"), fliplr (xs));
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
30 %! assert (sort (single (x)), single (xs));
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
31 %! assert (sort (single (x), "descend"), fliplr (single (xs)));
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
32
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
33 ## bug #44071, issorted incorrect because it uses different sort routine.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
34 %!assert (issorted ([1, -1, i, -i]), false)
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
35 %!assert (issorted (single ([1, -1, i, -i])), false)
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
36
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
37 ## bug #43313, -1 is both '>' and '==' to (-1 - 0i)
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
38 %!test
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
39 %! assert (complex(-1,0) == complex(-1,-0), true);
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
40 %! assert (complex(-1,0) > complex(-1,-0), false);
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
41 %! assert (complex(-1,0) < complex(-1,-0), false);
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
42
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
43 ## Test that sort and issorted both agree on boundary case
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
44 %!test
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
45 %! x = [complex(-1,0), complex(-1,-0), i, -i, 1];
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
46 %! xs = sort (x);
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
47 %! xf = single (x);
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
48 %! xfs = sort (xf);
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
49 %! assert (issorted (xs));
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
50 %! assert (issorted (xfs));
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19832
diff changeset
51 %! assert (double (xfs), xs);
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
52