Mercurial > octave-nkf
comparison src/OPERATORS/op-s-cs.cc @ 2928:295f037b4b3e
[project @ 1997-05-05 05:32:33 by jwe]
author | jwe |
---|---|
date | Mon, 05 May 1997 05:33:54 +0000 |
parents | |
children | 0ff7323dab8b |
comparison
equal
deleted
inserted
replaced
2927:8722c6284b72 | 2928:295f037b4b3e |
---|---|
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 | |
23 #if defined (__GNUG__) | |
24 #pragma implementation | |
25 #endif | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
31 #include "gripes.h" | |
32 #include "ov.h" | |
33 #include "ov-scalar.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 | |
41 // scalar by complex scalar ops. | |
42 | |
43 DEFBINOP_OP (add, scalar, complex, +) | |
44 DEFBINOP_OP (sub, scalar, complex, -) | |
45 DEFBINOP_OP (mul, scalar, complex, *) | |
46 | |
47 DEFBINOP (div, scalar, complex) | |
48 { | |
49 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
50 | |
51 Complex d = v2.complex_value (); | |
52 | |
53 if (d == 0.0) | |
54 gripe_divide_by_zero (); | |
55 | |
56 return octave_value (v1.double_value () / d); | |
57 } | |
58 | |
59 DEFBINOP_FN (pow, scalar, complex, xpow) | |
60 | |
61 DEFBINOP (ldiv, scalar, complex) | |
62 { | |
63 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
64 | |
65 double d = v1.double_value (); | |
66 | |
67 if (d == 0.0) | |
68 gripe_divide_by_zero (); | |
69 | |
70 return octave_value (v2.complex_value () / d); | |
71 } | |
72 | |
73 DEFBINOP (lt, scalar, complex) | |
74 { | |
75 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
76 | |
77 return v1.double_value () < real (v2.complex_value ()); | |
78 } | |
79 | |
80 DEFBINOP (le, scalar, complex) | |
81 { | |
82 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
83 | |
84 return v1.double_value () <= real (v2.complex_value ()); | |
85 } | |
86 | |
87 DEFBINOP (eq, scalar, complex) | |
88 { | |
89 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
90 | |
91 return v1.double_value () == v2.complex_value (); | |
92 } | |
93 | |
94 DEFBINOP (ge, scalar, complex) | |
95 { | |
96 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
97 | |
98 return v1.double_value () >= real (v2.complex_value ()); | |
99 } | |
100 | |
101 DEFBINOP (gt, scalar, complex) | |
102 { | |
103 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
104 | |
105 return v1.double_value () > real (v2.complex_value ()); | |
106 } | |
107 | |
108 DEFBINOP (ne, scalar, complex) | |
109 { | |
110 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
111 | |
112 return v1.double_value () != v2.complex_value (); | |
113 } | |
114 | |
115 DEFBINOP_OP (el_mul, scalar, complex, *) | |
116 | |
117 DEFBINOP (el_div, scalar, complex) | |
118 { | |
119 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
120 | |
121 Complex d = v2.complex_value (); | |
122 | |
123 if (d == 0.0) | |
124 gripe_divide_by_zero (); | |
125 | |
126 return octave_value (v1.double_value () / d); | |
127 } | |
128 | |
129 DEFBINOP_FN (el_pow, scalar, complex, xpow) | |
130 | |
131 DEFBINOP (el_ldiv, scalar, complex) | |
132 { | |
133 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
134 | |
135 double d = v1.double_value (); | |
136 | |
137 if (d == 0.0) | |
138 gripe_divide_by_zero (); | |
139 | |
140 return octave_value (v2.complex_value () / d); | |
141 } | |
142 | |
143 DEFBINOP (el_and, scalar, complex) | |
144 { | |
145 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
146 | |
147 return octave_value (v1.double_value () && (v2.complex_value () != 0.0)); | |
148 } | |
149 | |
150 DEFBINOP (el_or, scalar, complex) | |
151 { | |
152 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
153 | |
154 return octave_value (v1.double_value () || (v2.complex_value () != 0.0)); | |
155 } | |
156 | |
157 DEFCONV (complex_matrix_conv, scalar, complex_matrix) | |
158 { | |
159 CAST_CONV_ARG (const octave_scalar&); | |
160 | |
161 return new octave_complex_matrix (v.complex_matrix_value ()); | |
162 } | |
163 | |
164 void | |
165 install_s_cs_ops (void) | |
166 { | |
167 INSTALL_BINOP (add, octave_scalar, octave_complex, add); | |
168 INSTALL_BINOP (sub, octave_scalar, octave_complex, sub); | |
169 INSTALL_BINOP (mul, octave_scalar, octave_complex, mul); | |
170 INSTALL_BINOP (div, octave_scalar, octave_complex, div); | |
171 INSTALL_BINOP (pow, octave_scalar, octave_complex, pow); | |
172 INSTALL_BINOP (ldiv, octave_scalar, octave_complex, ldiv); | |
173 INSTALL_BINOP (lt, octave_scalar, octave_complex, lt); | |
174 INSTALL_BINOP (le, octave_scalar, octave_complex, le); | |
175 INSTALL_BINOP (eq, octave_scalar, octave_complex, eq); | |
176 INSTALL_BINOP (ge, octave_scalar, octave_complex, ge); | |
177 INSTALL_BINOP (gt, octave_scalar, octave_complex, gt); | |
178 INSTALL_BINOP (ne, octave_scalar, octave_complex, ne); | |
179 INSTALL_BINOP (el_mul, octave_scalar, octave_complex, el_mul); | |
180 INSTALL_BINOP (el_div, octave_scalar, octave_complex, el_div); | |
181 INSTALL_BINOP (el_pow, octave_scalar, octave_complex, el_pow); | |
182 INSTALL_BINOP (el_ldiv, octave_scalar, octave_complex, el_ldiv); | |
183 INSTALL_BINOP (el_and, octave_scalar, octave_complex, el_and); | |
184 INSTALL_BINOP (el_or, octave_scalar, octave_complex, el_or); | |
185 | |
186 INSTALL_ASSIGNCONV (octave_scalar, octave_complex, octave_complex_matrix); | |
187 | |
188 INSTALL_WIDENOP (octave_scalar, octave_complex_matrix, complex_matrix_conv); | |
189 } | |
190 | |
191 /* | |
192 ;;; Local Variables: *** | |
193 ;;; mode: C++ *** | |
194 ;;; End: *** | |
195 */ |