annotate test/complex.tst @ 19832:bdf90710dddf

Map -pi to pi for principal argument used in complex operators (bug #43313). * oct-cmplx.h: For all operator templates in file, use conditional tests on arg() output to effectively map -pi to pi. * Array-C.cc (nan_ascending_compare, nan_descending_compare) : Update sort routines used by issorted to map -pi to pi. Use intermediate variables for a 40% speed-up in calculation. * Array-fC.cc (nan_ascending_compare, nan_descending_compare) : Update sort routines used by issorted to map -pi to pi. Use intermediate variables for a 40% speed-up in calculation. * test/complex.tst: New test file to check behavior. * test/Makefile.am: Add complex.tst to build system.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Sat, 04 Oct 2014 02:17:17 -0500
parents
children 31e3799b9e27
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));
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
23
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 %!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
25 %! 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
26 %! 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
27 %! 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
28 %! assert (sort (x, "descend"), fliplr (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
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
diff changeset
30 ## 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
31 %!assert (issorted ([1, -1, i, -i]), 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
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 #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
34 %!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
35 %! 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
36 %! 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
37 %! 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
38
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 ## 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
40 %!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
41 %! 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
42 %! xs = sort (x);
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 %! assert (issorted (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
44