Mercurial > hg > octave-lyh
annotate src/OPERATORS/op-s-cs.cc @ 9621:3ee9029931b3
fix scalar complex-real comparisons
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 06 Sep 2009 07:41:34 +0200 |
parents | eb63fbe60fab |
children | ac4b97c6bf8b |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2007, 2008 |
7017 | 4 John W. Eaton |
2928 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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-scalar.h" | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
32 #include "ov-float.h" |
2928 | 33 #include "ov-complex.h" |
34 #include "ov-cx-mat.h" | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "ov-flt-cx-mat.h" |
2928 | 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 | |
9621
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
73 DEFCMPLXCMPOP_OP (lt, scalar, complex, <) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
74 DEFCMPLXCMPOP_OP (le, scalar, complex, <=) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
75 DEFCMPLXCMPOP_OP (eq, scalar, complex, ==) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
76 DEFCMPLXCMPOP_OP (ge, scalar, complex, >=) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
77 DEFCMPLXCMPOP_OP (gt, scalar, complex, >) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
78 DEFCMPLXCMPOP_OP (ne, scalar, complex, !=) |
2928 | 79 |
80 DEFBINOP_OP (el_mul, scalar, complex, *) | |
81 | |
82 DEFBINOP (el_div, scalar, complex) | |
83 { | |
84 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
85 | |
86 Complex d = v2.complex_value (); | |
87 | |
88 if (d == 0.0) | |
89 gripe_divide_by_zero (); | |
90 | |
91 return octave_value (v1.double_value () / d); | |
92 } | |
93 | |
94 DEFBINOP_FN (el_pow, scalar, complex, xpow) | |
95 | |
96 DEFBINOP (el_ldiv, scalar, complex) | |
97 { | |
98 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
99 | |
100 double d = v1.double_value (); | |
101 | |
102 if (d == 0.0) | |
103 gripe_divide_by_zero (); | |
104 | |
105 return octave_value (v2.complex_value () / d); | |
106 } | |
107 | |
108 DEFBINOP (el_and, scalar, complex) | |
109 { | |
110 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
111 | |
112 return octave_value (v1.double_value () && (v2.complex_value () != 0.0)); | |
113 } | |
114 | |
115 DEFBINOP (el_or, scalar, complex) | |
116 { | |
117 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&); | |
118 | |
119 return octave_value (v1.double_value () || (v2.complex_value () != 0.0)); | |
120 } | |
121 | |
4915 | 122 DEFNDCATOP_FN (s_cs, scalar, complex, array, complex_array, concat) |
123 | |
2928 | 124 void |
125 install_s_cs_ops (void) | |
126 { | |
3538 | 127 INSTALL_BINOP (op_add, octave_scalar, octave_complex, add); |
128 INSTALL_BINOP (op_sub, octave_scalar, octave_complex, sub); | |
129 INSTALL_BINOP (op_mul, octave_scalar, octave_complex, mul); | |
130 INSTALL_BINOP (op_div, octave_scalar, octave_complex, div); | |
131 INSTALL_BINOP (op_pow, octave_scalar, octave_complex, pow); | |
132 INSTALL_BINOP (op_ldiv, octave_scalar, octave_complex, ldiv); | |
133 INSTALL_BINOP (op_lt, octave_scalar, octave_complex, lt); | |
134 INSTALL_BINOP (op_le, octave_scalar, octave_complex, le); | |
135 INSTALL_BINOP (op_eq, octave_scalar, octave_complex, eq); | |
136 INSTALL_BINOP (op_ge, octave_scalar, octave_complex, ge); | |
137 INSTALL_BINOP (op_gt, octave_scalar, octave_complex, gt); | |
138 INSTALL_BINOP (op_ne, octave_scalar, octave_complex, ne); | |
139 INSTALL_BINOP (op_el_mul, octave_scalar, octave_complex, el_mul); | |
140 INSTALL_BINOP (op_el_div, octave_scalar, octave_complex, el_div); | |
141 INSTALL_BINOP (op_el_pow, octave_scalar, octave_complex, el_pow); | |
142 INSTALL_BINOP (op_el_ldiv, octave_scalar, octave_complex, el_ldiv); | |
143 INSTALL_BINOP (op_el_and, octave_scalar, octave_complex, el_and); | |
144 INSTALL_BINOP (op_el_or, octave_scalar, octave_complex, el_or); | |
2928 | 145 |
4915 | 146 INSTALL_CATOP (octave_scalar, octave_complex, s_cs); |
147 | |
2928 | 148 INSTALL_ASSIGNCONV (octave_scalar, octave_complex, octave_complex_matrix); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 INSTALL_ASSIGNCONV (octave_float_scalar, octave_complex, octave_float_complex_matrix); |
2928 | 150 } |
151 | |
152 /* | |
153 ;;; Local Variables: *** | |
154 ;;; mode: C++ *** | |
155 ;;; End: *** | |
156 */ |