2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2928
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "gripes.h" |
4055
|
32 #include "oct-obj.h" |
2928
|
33 #include "ov.h" |
|
34 #include "ov-complex.h" |
|
35 #include "ov-cx-mat.h" |
|
36 #include "ov-typeinfo.h" |
|
37 #include "ops.h" |
|
38 #include "xdiv.h" |
|
39 #include "xpow.h" |
|
40 |
3203
|
41 // unary complex scalar ops. |
|
42 |
|
43 DEFUNOP (not, complex) |
|
44 { |
|
45 CAST_UNOP_ARG (const octave_complex&); |
|
46 |
|
47 return octave_value (v.complex_value () == 0.0); |
|
48 } |
|
49 |
|
50 DEFUNOP_OP (uminus, complex, -) |
|
51 DEFUNOP_OP (transpose, complex, /* no-op */) |
|
52 |
|
53 DEFUNOP (hermitian, complex) |
|
54 { |
|
55 CAST_UNOP_ARG (const octave_complex&); |
|
56 |
|
57 return octave_value (conj (v.complex_value ())); |
|
58 } |
|
59 |
|
60 DEFNCUNOP_METHOD (incr, complex, increment) |
|
61 DEFNCUNOP_METHOD (decr, complex, decrement) |
|
62 |
2928
|
63 // complex scalar by complex scalar ops. |
|
64 |
|
65 DEFBINOP_OP (add, complex, complex, +) |
|
66 DEFBINOP_OP (sub, complex, complex, -) |
|
67 DEFBINOP_OP (mul, complex, complex, *) |
|
68 |
|
69 DEFBINOP (div, complex, complex) |
|
70 { |
|
71 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
72 |
|
73 Complex d = v2.complex_value (); |
|
74 |
|
75 if (d == 0.0) |
|
76 gripe_divide_by_zero (); |
|
77 |
|
78 return octave_value (v1.complex_value () / d); |
|
79 } |
|
80 |
|
81 DEFBINOP_FN (pow, complex, complex, xpow) |
|
82 |
|
83 DEFBINOP (ldiv, complex, complex) |
|
84 { |
|
85 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
86 |
|
87 Complex d = v1.complex_value (); |
|
88 |
|
89 if (d == 0.0) |
|
90 gripe_divide_by_zero (); |
|
91 |
|
92 return octave_value (v2.complex_value () / d); |
|
93 } |
|
94 |
|
95 DEFBINOP (lt, complex, complex) |
|
96 { |
|
97 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
98 |
|
99 return real (v1.complex_value ()) < real (v2.complex_value ()); |
|
100 } |
|
101 |
|
102 DEFBINOP (le, complex, complex) |
|
103 { |
|
104 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
105 |
|
106 return real (v1.complex_value ()) <= real (v2.complex_value ()); |
|
107 } |
|
108 |
|
109 DEFBINOP (eq, complex, complex) |
|
110 { |
|
111 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
112 |
|
113 return v1.complex_value () == v2.complex_value (); |
|
114 } |
|
115 |
|
116 DEFBINOP (ge, complex, complex) |
|
117 { |
|
118 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
119 |
|
120 return real (v1.complex_value ()) >= real (v2.complex_value ()); |
|
121 } |
|
122 |
|
123 DEFBINOP (gt, complex, complex) |
|
124 { |
|
125 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
126 |
|
127 return real (v1.complex_value ()) > real (v2.complex_value ()); |
|
128 } |
|
129 |
|
130 DEFBINOP (ne, complex, complex) |
|
131 { |
|
132 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
133 |
|
134 return v1.complex_value () != v2.complex_value (); |
|
135 } |
|
136 |
|
137 DEFBINOP_OP (el_mul, complex, complex, *) |
|
138 |
|
139 DEFBINOP (el_div, complex, complex) |
|
140 { |
|
141 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
142 |
|
143 Complex d = v2.complex_value (); |
|
144 |
|
145 if (d == 0.0) |
|
146 gripe_divide_by_zero (); |
|
147 |
|
148 return octave_value (v1.complex_value () / d); |
|
149 } |
|
150 |
|
151 DEFBINOP_FN (el_pow, complex, complex, xpow) |
|
152 |
|
153 DEFBINOP (el_ldiv, complex, complex) |
|
154 { |
|
155 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
156 |
|
157 Complex d = v1.complex_value (); |
|
158 |
|
159 if (d == 0.0) |
|
160 gripe_divide_by_zero (); |
|
161 |
|
162 return octave_value (v2.complex_value () / d); |
|
163 } |
|
164 |
|
165 DEFBINOP (el_and, complex, complex) |
|
166 { |
|
167 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
168 |
|
169 return v1.complex_value () != 0.0 && v2.complex_value () != 0.0; |
|
170 } |
|
171 |
|
172 DEFBINOP (el_or, complex, complex) |
|
173 { |
|
174 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
175 |
|
176 return v1.complex_value () != 0.0 || v2.complex_value () != 0.0; |
|
177 } |
|
178 |
|
179 void |
|
180 install_cs_cs_ops (void) |
|
181 { |
3538
|
182 INSTALL_UNOP (op_not, octave_complex, not); |
|
183 INSTALL_UNOP (op_uminus, octave_complex, uminus); |
|
184 INSTALL_UNOP (op_transpose, octave_complex, transpose); |
|
185 INSTALL_UNOP (op_hermitian, octave_complex, hermitian); |
3203
|
186 |
3538
|
187 INSTALL_NCUNOP (op_incr, octave_complex, incr); |
|
188 INSTALL_NCUNOP (op_decr, octave_complex, decr); |
3203
|
189 |
3538
|
190 INSTALL_BINOP (op_add, octave_complex, octave_complex, add); |
|
191 INSTALL_BINOP (op_sub, octave_complex, octave_complex, sub); |
|
192 INSTALL_BINOP (op_mul, octave_complex, octave_complex, mul); |
|
193 INSTALL_BINOP (op_div, octave_complex, octave_complex, div); |
|
194 INSTALL_BINOP (op_pow, octave_complex, octave_complex, pow); |
|
195 INSTALL_BINOP (op_ldiv, octave_complex, octave_complex, ldiv); |
|
196 INSTALL_BINOP (op_lt, octave_complex, octave_complex, lt); |
|
197 INSTALL_BINOP (op_le, octave_complex, octave_complex, le); |
|
198 INSTALL_BINOP (op_eq, octave_complex, octave_complex, eq); |
|
199 INSTALL_BINOP (op_ge, octave_complex, octave_complex, ge); |
|
200 INSTALL_BINOP (op_gt, octave_complex, octave_complex, gt); |
|
201 INSTALL_BINOP (op_ne, octave_complex, octave_complex, ne); |
|
202 INSTALL_BINOP (op_el_mul, octave_complex, octave_complex, el_mul); |
|
203 INSTALL_BINOP (op_el_div, octave_complex, octave_complex, el_div); |
|
204 INSTALL_BINOP (op_el_pow, octave_complex, octave_complex, el_pow); |
|
205 INSTALL_BINOP (op_el_ldiv, octave_complex, octave_complex, el_ldiv); |
|
206 INSTALL_BINOP (op_el_and, octave_complex, octave_complex, el_and); |
|
207 INSTALL_BINOP (op_el_or, octave_complex, octave_complex, el_or); |
2928
|
208 |
|
209 INSTALL_ASSIGNCONV (octave_complex, octave_complex, octave_complex_matrix); |
|
210 } |
|
211 |
|
212 /* |
|
213 ;;; Local Variables: *** |
|
214 ;;; mode: C++ *** |
|
215 ;;; End: *** |
|
216 */ |