33
|
1 // tc-givens.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1993 John W. Eaton |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
25 |
|
26 #ifdef __GNUG__ |
|
27 #pragma implementation |
|
28 #endif |
|
29 |
|
30 #include "Matrix.h" |
|
31 |
|
32 #include "tree-const.h" |
|
33 #include "user-prefs.h" |
|
34 #include "error.h" |
|
35 #include "gripes.h" |
|
36 |
47
|
37 extern "C" |
|
38 { |
|
39 int F77_FCN (dlartg) (const double*, const double*, double*, double*, |
|
40 double*); |
33
|
41 |
47
|
42 int F77_FCN (zlartg) (const Complex*, const Complex*, double*, |
|
43 Complex*, Complex*); |
|
44 } |
33
|
45 |
|
46 // These aren't used? |
|
47 #if 0 |
|
48 int F77_FCN (dorgqr) (const int*, const int*, const int*, double*, |
|
49 const int*, double*, double*, const int*, int*); |
|
50 |
|
51 int F77_FCN (zunghr) (const int*, const int*, const int*, Complex*, |
|
52 const int*, Complex*, Complex*, const int*, |
|
53 int*, long, long); |
|
54 #endif |
|
55 |
|
56 #ifdef WITH_DLD |
|
57 tree_constant * |
|
58 builtin_givens_2 (tree_constant *args, int nargin, int nargout) |
|
59 { |
|
60 return givens (args, nargin, nargout); |
|
61 } |
|
62 #endif |
|
63 |
|
64 tree_constant * |
|
65 givens (tree_constant *args, int nargin, int nargout) |
|
66 { |
|
67 |
|
68 tree_constant *retval = NULL_TREE_CONST; |
|
69 |
|
70 tree_constant arga = args[1].make_numeric (); |
|
71 tree_constant argb = args[2].make_numeric (); |
|
72 |
|
73 if (! arga.is_scalar_type () && argb.is_scalar_type ()) |
|
74 { |
|
75 error("givens: requires two scalar arguments"); |
|
76 } |
|
77 else |
|
78 { |
|
79 |
|
80 retval = new tree_constant [nargout+1]; |
|
81 |
|
82 Complex cx, cy; |
|
83 double x, y; |
|
84 |
|
85 if (arga.is_complex_type ()) |
|
86 cx = arga.complex_value (); |
|
87 else |
|
88 { |
|
89 x = arga.double_value (); |
|
90 cx = x; // copy to complex just in case |
|
91 } |
|
92 |
|
93 if (argb.is_complex_type ()) |
|
94 cy = argb.complex_value (); |
|
95 else |
|
96 { |
|
97 y = argb.double_value (); |
|
98 cy = y; // copy to complex just in case |
|
99 } |
|
100 |
|
101 // Now compute the rotation. |
|
102 |
|
103 double cc; |
|
104 if (arga.is_complex_type () || argb.is_complex_type ()) |
|
105 { |
|
106 Complex cs, temp_r; |
|
107 |
|
108 F77_FCN (zlartg) (&cx, &cy, &cc, &cs, &temp_r); |
|
109 |
|
110 switch (nargout) |
|
111 { |
|
112 case 1: // output a matrix |
|
113 { |
|
114 ComplexMatrix g (2, 2); |
|
115 g.elem (0, 0) = cc; |
|
116 g.elem (1, 1) = cc; |
|
117 g.elem (0, 1) = cs; |
|
118 g.elem (1, 0) = -conj (cs); |
|
119 |
|
120 retval[0] = tree_constant (g); |
|
121 } |
|
122 break; |
|
123 |
|
124 case 2: // output scalar values |
|
125 retval[0] = tree_constant(cc); |
|
126 retval[1] = tree_constant(cs); |
|
127 break; |
|
128 |
|
129 default: |
|
130 error ("givens: illegal number of output arguments"); |
|
131 break; |
|
132 } |
|
133 } |
|
134 else |
|
135 { |
|
136 double s, temp_r; |
|
137 |
|
138 F77_FCN (dlartg) (&x, &y, &cc, &s, &temp_r); |
|
139 |
|
140 switch (nargout) |
|
141 { |
|
142 case 1: // output a matrix |
|
143 { |
|
144 Matrix g (2, 2); |
|
145 g.elem (0, 0) = cc; |
|
146 g.elem (1, 1) = cc; |
|
147 g.elem (0, 1) = s; |
|
148 g.elem (1, 0) = -s; |
|
149 |
|
150 retval[0] = tree_constant (g); |
|
151 } |
|
152 break; |
|
153 |
|
154 case 2: // output scalar values |
|
155 retval[0] = tree_constant (cc); |
|
156 retval[1] = tree_constant (s); |
|
157 break; |
|
158 |
|
159 default: |
|
160 error ("givens: illegal number of output arguments"); |
|
161 break; |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 return retval; |
|
167 } |
|
168 |
|
169 /* |
|
170 ;;; Local Variables: *** |
|
171 ;;; mode: C++ *** |
|
172 ;;; page-delimiter: "^/\\*" *** |
|
173 ;;; End: *** |
|
174 */ |