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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "gripes.h" |
4055
|
29 #include "oct-obj.h" |
2928
|
30 #include "ov.h" |
|
31 #include "ov-complex.h" |
|
32 #include "ov-cx-mat.h" |
|
33 #include "ov-scalar.h" |
|
34 #include "ov-typeinfo.h" |
|
35 #include "ops.h" |
|
36 #include "xdiv.h" |
|
37 #include "xpow.h" |
|
38 |
|
39 // complex scalar by scalar ops. |
|
40 |
|
41 DEFBINOP_OP (add, complex, scalar, +) |
|
42 DEFBINOP_OP (sub, complex, scalar, -) |
|
43 DEFBINOP_OP (mul, complex, scalar, *) |
|
44 |
|
45 DEFBINOP (div, complex, scalar) |
|
46 { |
|
47 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
48 |
|
49 double d = v2.double_value (); |
|
50 |
|
51 if (d == 0.0) |
|
52 gripe_divide_by_zero (); |
|
53 |
|
54 return octave_value (v1.complex_value () / d); |
|
55 } |
|
56 |
|
57 DEFBINOP_FN (pow, complex, scalar, xpow) |
|
58 |
|
59 DEFBINOP (ldiv, complex, scalar) |
|
60 { |
|
61 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
62 |
3055
|
63 Complex d = v1.complex_value (); |
2928
|
64 |
|
65 if (d == 0.0) |
|
66 gripe_divide_by_zero (); |
|
67 |
3054
|
68 return octave_value (v2.double_value () / d); |
2928
|
69 } |
|
70 |
|
71 DEFBINOP (lt, complex, scalar) |
|
72 { |
|
73 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
74 |
|
75 return real (v1.complex_value ()) < v2.double_value (); |
|
76 } |
|
77 |
|
78 DEFBINOP (le, complex, scalar) |
|
79 { |
|
80 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
81 |
|
82 return real (v1.complex_value ()) <= v2.double_value (); |
|
83 } |
|
84 |
|
85 DEFBINOP (eq, complex, scalar) |
|
86 { |
|
87 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
88 |
|
89 return v1.complex_value () == v2.double_value (); |
|
90 } |
|
91 |
|
92 DEFBINOP (ge, complex, scalar) |
|
93 { |
|
94 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
95 |
|
96 return real (v1.complex_value ()) >= v2.double_value (); |
|
97 } |
|
98 |
|
99 DEFBINOP (gt, complex, scalar) |
|
100 { |
|
101 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
102 |
|
103 return real (v1.complex_value ()) > v2.double_value (); |
|
104 } |
|
105 |
|
106 DEFBINOP (ne, complex, scalar) |
|
107 { |
|
108 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
109 |
|
110 return v1.complex_value () != v2.double_value (); |
|
111 } |
|
112 |
|
113 DEFBINOP_OP (el_mul, complex, scalar, *) |
|
114 |
|
115 DEFBINOP (el_div, complex, scalar) |
|
116 { |
|
117 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
118 |
|
119 double d = v2.double_value (); |
|
120 |
|
121 if (d == 0.0) |
|
122 gripe_divide_by_zero (); |
|
123 |
|
124 return octave_value (v1.complex_value () / d); |
|
125 } |
|
126 |
|
127 DEFBINOP_FN (el_pow, complex, scalar, xpow) |
|
128 |
|
129 DEFBINOP (el_ldiv, complex, scalar) |
|
130 { |
|
131 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
132 |
4502
|
133 Complex d = v1.complex_value (); |
2928
|
134 |
|
135 if (d == 0.0) |
|
136 gripe_divide_by_zero (); |
|
137 |
4502
|
138 return octave_value (v2.double_value () / d); |
2928
|
139 } |
|
140 |
|
141 DEFBINOP (el_and, complex, scalar) |
|
142 { |
|
143 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
144 |
|
145 return v1.complex_value () != 0.0 && v2.double_value (); |
|
146 } |
|
147 |
|
148 DEFBINOP (el_or, complex, scalar) |
|
149 { |
|
150 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&); |
|
151 |
|
152 return v1.complex_value () != 0.0 || v2.double_value (); |
|
153 } |
|
154 |
4915
|
155 DEFNDCATOP_FN (cs_s, complex, scalar, complex_array, array, concat) |
|
156 |
2928
|
157 void |
|
158 install_cs_s_ops (void) |
|
159 { |
3538
|
160 INSTALL_BINOP (op_add, octave_complex, octave_scalar, add); |
|
161 INSTALL_BINOP (op_sub, octave_complex, octave_scalar, sub); |
|
162 INSTALL_BINOP (op_mul, octave_complex, octave_scalar, mul); |
|
163 INSTALL_BINOP (op_div, octave_complex, octave_scalar, div); |
|
164 INSTALL_BINOP (op_pow, octave_complex, octave_scalar, pow); |
|
165 INSTALL_BINOP (op_ldiv, octave_complex, octave_scalar, ldiv); |
|
166 INSTALL_BINOP (op_lt, octave_complex, octave_scalar, lt); |
|
167 INSTALL_BINOP (op_le, octave_complex, octave_scalar, le); |
|
168 INSTALL_BINOP (op_eq, octave_complex, octave_scalar, eq); |
|
169 INSTALL_BINOP (op_ge, octave_complex, octave_scalar, ge); |
|
170 INSTALL_BINOP (op_gt, octave_complex, octave_scalar, gt); |
|
171 INSTALL_BINOP (op_ne, octave_complex, octave_scalar, ne); |
|
172 INSTALL_BINOP (op_el_mul, octave_complex, octave_scalar, el_mul); |
|
173 INSTALL_BINOP (op_el_div, octave_complex, octave_scalar, el_div); |
|
174 INSTALL_BINOP (op_el_pow, octave_complex, octave_scalar, el_pow); |
|
175 INSTALL_BINOP (op_el_ldiv, octave_complex, octave_scalar, el_ldiv); |
|
176 INSTALL_BINOP (op_el_and, octave_complex, octave_scalar, el_and); |
|
177 INSTALL_BINOP (op_el_or, octave_complex, octave_scalar, el_or); |
2928
|
178 |
4915
|
179 INSTALL_CATOP (octave_complex, octave_scalar, cs_s); |
|
180 |
2928
|
181 INSTALL_ASSIGNCONV (octave_complex, octave_scalar, octave_complex_matrix); |
|
182 } |
|
183 |
|
184 /* |
|
185 ;;; Local Variables: *** |
|
186 ;;; mode: C++ *** |
|
187 ;;; End: *** |
|
188 */ |