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