4878
|
1 ## Copyright (C) 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4878
|
9 ## |
7016
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
4878
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4878
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} com2str (@var{zz}, @var{flg}) |
|
21 ## This function has been deprecated. Use num2str instead. |
|
22 ## |
|
23 ## Convert complex number to a string. |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item zz |
|
27 ## complex number |
|
28 ## @item flg |
|
29 ## format flag |
|
30 ## 0 (default): -1, 0, 1, 1i, 1 + 0.5i |
|
31 ## 1 (for use with zpout): -1, 0, + 1, + 1i, + 1 + 0.5i |
|
32 ## @end table |
|
33 ## @end deftypefn |
|
34 |
|
35 function retval = com2str (zz, flg) |
|
36 |
|
37 if (nargin < 1 || nargin > 2) |
6046
|
38 print_usage (); |
4878
|
39 endif |
|
40 if (nargin == 1) |
|
41 flg = 0; |
|
42 endif |
|
43 |
|
44 if (! (isscalar (zz) && isscalar (flg))) |
|
45 error ("com2str: arguments must be a scalar"); |
|
46 endif |
|
47 |
|
48 if (flg != 0 && flg != 1) |
|
49 error ("invalid flg value: %d", flg); |
|
50 endif |
|
51 |
|
52 sgns = "+-"; |
|
53 rz = real (zz); |
|
54 iz = imag (zz); |
|
55 az = abs (zz); |
|
56 if (iz == 0) |
|
57 ## strictly a real number |
|
58 switch (flg) |
|
59 case(0) |
|
60 retval = num2str (rz); |
|
61 case(1) |
|
62 retval = [sgns(1+(rz<0)), " ", num2str(abs(rz))]; |
|
63 endswitch |
|
64 elseif (rz == 0) |
|
65 ## strictly an imaginary number |
|
66 switch (flg) |
|
67 case(0) |
4898
|
68 retval = [num2str(iz), "i"]; |
4878
|
69 case(1) |
|
70 retval = [sgns(1+(iz<0)), " ", num2str(abs(iz)), "i"]; |
|
71 endswitch |
|
72 else |
|
73 ## complex number |
|
74 ## strictly an imaginary number |
|
75 switch (flg) |
|
76 case(0) |
|
77 retval = [num2str(rz), " ", com2str(i*iz,1)]; |
|
78 case(1) |
|
79 retval = [sgns(1+(rz<0)), " ", num2str(abs(rz)), " ", com2str(i*iz,1)]; |
|
80 endswitch |
|
81 endif |
|
82 |
|
83 endfunction |