op-cs-cs.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "Array-util.h"
00028 
00029 #include "gripes.h"
00030 #include "oct-obj.h"
00031 #include "ov.h"
00032 #include "ov-complex.h"
00033 #include "ov-cx-mat.h"
00034 #include "ov-flt-cx-mat.h"
00035 #include "ov-typeinfo.h"
00036 #include "ov-null-mat.h"
00037 #include "ops.h"
00038 #include "xdiv.h"
00039 #include "xpow.h"
00040 
00041 // unary complex scalar ops.
00042 
00043 DEFUNOP (not, complex)
00044 {
00045   CAST_UNOP_ARG (const octave_complex&);
00046   Complex x = v.complex_value ();
00047   if (xisnan (x))
00048     gripe_nan_to_logical_conversion ();
00049   return octave_value (x == 0.0);
00050 }
00051 
00052 DEFUNOP_OP (uplus, complex, /* no-op */)
00053 DEFUNOP_OP (uminus, complex, -)
00054 DEFUNOP_OP (transpose, complex, /* no-op */)
00055 
00056 DEFUNOP (hermitian, complex)
00057 {
00058   CAST_UNOP_ARG (const octave_complex&);
00059 
00060   return octave_value (conj (v.complex_value ()));
00061 }
00062 
00063 DEFNCUNOP_METHOD (incr, complex, increment)
00064 DEFNCUNOP_METHOD (decr, complex, decrement)
00065 
00066 // complex scalar by complex scalar ops.
00067 
00068 DEFBINOP_OP (add, complex, complex, +)
00069 DEFBINOP_OP (sub, complex, complex, -)
00070 DEFBINOP_OP (mul, complex, complex, *)
00071 
00072 DEFBINOP (div, complex, complex)
00073 {
00074   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00075 
00076   Complex d = v2.complex_value ();
00077 
00078   if (d == 0.0)
00079     gripe_divide_by_zero ();
00080 
00081   return octave_value (v1.complex_value () / d);
00082 }
00083 
00084 DEFBINOP_FN (pow, complex, complex, xpow)
00085 
00086 DEFBINOP (ldiv, complex, complex)
00087 {
00088   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00089 
00090   Complex d = v1.complex_value ();
00091 
00092   if (d == 0.0)
00093     gripe_divide_by_zero ();
00094 
00095   return octave_value (v2.complex_value () / d);
00096 }
00097 
00098 DEFCMPLXCMPOP_OP (lt, complex, complex, <)
00099 DEFCMPLXCMPOP_OP (le, complex, complex, <=)
00100 DEFCMPLXCMPOP_OP (eq, complex, complex, ==)
00101 DEFCMPLXCMPOP_OP (ge, complex, complex, >=)
00102 DEFCMPLXCMPOP_OP (gt, complex, complex, >)
00103 DEFCMPLXCMPOP_OP (ne, complex, complex, !=)
00104 
00105 DEFBINOP_OP (el_mul, complex, complex, *)
00106 
00107 DEFBINOP (el_div, complex, complex)
00108 {
00109   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00110 
00111   Complex d = v2.complex_value ();
00112 
00113   if (d == 0.0)
00114     gripe_divide_by_zero ();
00115 
00116   return octave_value (v1.complex_value () / d);
00117 }
00118 
00119 DEFBINOP_FN (el_pow, complex, complex, xpow)
00120 
00121 DEFBINOP (el_ldiv, complex, complex)
00122 {
00123   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00124 
00125   Complex d = v1.complex_value ();
00126 
00127   if (d == 0.0)
00128     gripe_divide_by_zero ();
00129 
00130   return octave_value (v2.complex_value () / d);
00131 }
00132 
00133 DEFBINOP (el_and, complex, complex)
00134 {
00135   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00136 
00137   return v1.complex_value () != 0.0 && v2.complex_value () != 0.0;
00138 }
00139 
00140 DEFBINOP (el_or, complex, complex)
00141 {
00142   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
00143 
00144   return v1.complex_value () != 0.0 || v2.complex_value () != 0.0;
00145 }
00146 
00147 DEFNDCATOP_FN (cs_cs, complex, complex, complex_array, complex_array, concat)
00148 
00149 CONVDECL (complex_to_float_complex)
00150 {
00151   CAST_CONV_ARG (const octave_complex&);
00152 
00153   return new octave_float_complex_matrix (FloatComplexMatrix (1, 1, static_cast<FloatComplex>(v.complex_value ())));
00154 }
00155 
00156 void
00157 install_cs_cs_ops (void)
00158 {
00159   INSTALL_UNOP (op_not, octave_complex, not);
00160   INSTALL_UNOP (op_uplus, octave_complex, uplus);
00161   INSTALL_UNOP (op_uminus, octave_complex, uminus);
00162   INSTALL_UNOP (op_transpose, octave_complex, transpose);
00163   INSTALL_UNOP (op_hermitian, octave_complex, hermitian);
00164 
00165   INSTALL_NCUNOP (op_incr, octave_complex, incr);
00166   INSTALL_NCUNOP (op_decr, octave_complex, decr);
00167 
00168   INSTALL_BINOP (op_add, octave_complex, octave_complex, add);
00169   INSTALL_BINOP (op_sub, octave_complex, octave_complex, sub);
00170   INSTALL_BINOP (op_mul, octave_complex, octave_complex, mul);
00171   INSTALL_BINOP (op_div, octave_complex, octave_complex, div);
00172   INSTALL_BINOP (op_pow, octave_complex, octave_complex, pow);
00173   INSTALL_BINOP (op_ldiv, octave_complex, octave_complex, ldiv);
00174   INSTALL_BINOP (op_lt, octave_complex, octave_complex, lt);
00175   INSTALL_BINOP (op_le, octave_complex, octave_complex, le);
00176   INSTALL_BINOP (op_eq, octave_complex, octave_complex, eq);
00177   INSTALL_BINOP (op_ge, octave_complex, octave_complex, ge);
00178   INSTALL_BINOP (op_gt, octave_complex, octave_complex, gt);
00179   INSTALL_BINOP (op_ne, octave_complex, octave_complex, ne);
00180   INSTALL_BINOP (op_el_mul, octave_complex, octave_complex, el_mul);
00181   INSTALL_BINOP (op_el_div, octave_complex, octave_complex, el_div);
00182   INSTALL_BINOP (op_el_pow, octave_complex, octave_complex, el_pow);
00183   INSTALL_BINOP (op_el_ldiv, octave_complex, octave_complex, el_ldiv);
00184   INSTALL_BINOP (op_el_and, octave_complex, octave_complex, el_and);
00185   INSTALL_BINOP (op_el_or, octave_complex, octave_complex, el_or);
00186 
00187   INSTALL_CATOP (octave_complex, octave_complex, cs_cs);
00188 
00189   INSTALL_ASSIGNCONV (octave_complex, octave_complex, octave_complex_matrix);
00190 
00191   INSTALL_ASSIGNCONV (octave_complex, octave_null_matrix, octave_complex_matrix);
00192   INSTALL_ASSIGNCONV (octave_complex, octave_null_str, octave_complex_matrix);
00193   INSTALL_ASSIGNCONV (octave_complex, octave_null_sq_str, octave_complex_matrix);
00194 
00195   INSTALL_CONVOP (octave_complex, octave_float_complex_matrix,
00196                   complex_to_float_complex);
00197 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines