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-re-mat.h" |
|
35 #include "ov-scalar.h" |
|
36 #include "ov-typeinfo.h" |
|
37 #include "ops.h" |
|
38 #include "xdiv.h" |
|
39 #include "xpow.h" |
|
40 |
|
41 // matrix by scalar ops. |
|
42 |
|
43 DEFBINOP_OP (add, matrix, scalar, +) |
|
44 DEFBINOP_OP (sub, matrix, scalar, -) |
|
45 DEFBINOP_OP (mul, matrix, scalar, *) |
|
46 |
|
47 DEFBINOP (div, matrix, scalar) |
|
48 { |
|
49 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
50 |
|
51 double d = v2.double_value (); |
|
52 |
|
53 if (d == 0.0) |
|
54 gripe_divide_by_zero (); |
|
55 |
|
56 return octave_value (v1.matrix_value () / d); |
|
57 } |
|
58 |
|
59 DEFBINOP_FN (pow, matrix, scalar, xpow) |
|
60 |
|
61 DEFBINOP (ldiv, matrix, scalar) |
|
62 { |
3766
|
63 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
64 |
|
65 Matrix m1 = v1.matrix_value (); |
|
66 Matrix m2 = v2.matrix_value (); |
|
67 |
|
68 return octave_value (xleftdiv (m1, m2)); |
2928
|
69 } |
|
70 |
|
71 DEFBINOP_FN (lt, matrix, scalar, mx_el_lt) |
|
72 DEFBINOP_FN (le, matrix, scalar, mx_el_le) |
|
73 DEFBINOP_FN (eq, matrix, scalar, mx_el_eq) |
|
74 DEFBINOP_FN (ge, matrix, scalar, mx_el_ge) |
|
75 DEFBINOP_FN (gt, matrix, scalar, mx_el_gt) |
|
76 DEFBINOP_FN (ne, matrix, scalar, mx_el_ne) |
|
77 |
|
78 DEFBINOP_OP (el_mul, matrix, scalar, *) |
|
79 |
|
80 DEFBINOP (el_div, matrix, scalar) |
|
81 { |
|
82 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
83 |
|
84 double d = v2.double_value (); |
|
85 |
|
86 if (d == 0.0) |
|
87 gripe_divide_by_zero (); |
|
88 |
|
89 return octave_value (v1.matrix_value () / d); |
|
90 } |
|
91 |
|
92 DEFBINOP_FN (el_pow, matrix, scalar, elem_xpow) |
|
93 |
|
94 DEFBINOP (el_ldiv, matrix, scalar) |
|
95 { |
|
96 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
97 |
|
98 return x_el_div (v2.double_value (), v1.matrix_value ()); |
|
99 } |
|
100 |
|
101 DEFBINOP_FN (el_and, matrix, scalar, mx_el_and) |
|
102 DEFBINOP_FN (el_or, matrix, scalar, mx_el_or) |
|
103 |
|
104 DEFASSIGNOP_FN (assign, matrix, scalar, assign) |
|
105 |
|
106 void |
|
107 install_m_s_ops (void) |
|
108 { |
3538
|
109 INSTALL_BINOP (op_add, octave_matrix, octave_scalar, add); |
|
110 INSTALL_BINOP (op_sub, octave_matrix, octave_scalar, sub); |
|
111 INSTALL_BINOP (op_mul, octave_matrix, octave_scalar, mul); |
|
112 INSTALL_BINOP (op_div, octave_matrix, octave_scalar, div); |
|
113 INSTALL_BINOP (op_pow, octave_matrix, octave_scalar, pow); |
|
114 INSTALL_BINOP (op_ldiv, octave_matrix, octave_scalar, ldiv); |
|
115 INSTALL_BINOP (op_lt, octave_matrix, octave_scalar, lt); |
|
116 INSTALL_BINOP (op_le, octave_matrix, octave_scalar, le); |
|
117 INSTALL_BINOP (op_eq, octave_matrix, octave_scalar, eq); |
|
118 INSTALL_BINOP (op_ge, octave_matrix, octave_scalar, ge); |
|
119 INSTALL_BINOP (op_gt, octave_matrix, octave_scalar, gt); |
|
120 INSTALL_BINOP (op_ne, octave_matrix, octave_scalar, ne); |
|
121 INSTALL_BINOP (op_el_mul, octave_matrix, octave_scalar, el_mul); |
|
122 INSTALL_BINOP (op_el_div, octave_matrix, octave_scalar, el_div); |
|
123 INSTALL_BINOP (op_el_pow, octave_matrix, octave_scalar, el_pow); |
|
124 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_scalar, el_ldiv); |
|
125 INSTALL_BINOP (op_el_and, octave_matrix, octave_scalar, el_and); |
|
126 INSTALL_BINOP (op_el_or, octave_matrix, octave_scalar, el_or); |
2928
|
127 |
3538
|
128 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_scalar, assign); |
2928
|
129 } |
|
130 |
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; End: *** |
|
135 */ |