op-cs-s.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 "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-complex.h"
00031 #include "ov-cx-mat.h"
00032 #include "ov-scalar.h"
00033 #include "ov-typeinfo.h"
00034 #include "ops.h"
00035 #include "xdiv.h"
00036 #include "xpow.h"
00037 
00038 // complex scalar by scalar ops.
00039 
00040 DEFBINOP_OP (add, complex, scalar, +)
00041 DEFBINOP_OP (sub, complex, scalar, -)
00042 DEFBINOP_OP (mul, complex, scalar, *)
00043 
00044 DEFBINOP (div, complex, scalar)
00045 {
00046   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00047 
00048   double d = v2.double_value ();
00049 
00050   if (d == 0.0)
00051     gripe_divide_by_zero ();
00052 
00053   return octave_value (v1.complex_value () / d);
00054 }
00055 
00056 DEFBINOP_FN (pow, complex, scalar, xpow)
00057 
00058 DEFBINOP (ldiv, complex, scalar)
00059 {
00060   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00061 
00062   Complex d = v1.complex_value ();
00063 
00064   if (d == 0.0)
00065     gripe_divide_by_zero ();
00066 
00067   return octave_value (v2.double_value () / d);
00068 }
00069 
00070 DEFCMPLXCMPOP_OP (lt, complex, scalar, <)
00071 DEFCMPLXCMPOP_OP (le, complex, scalar, <=)
00072 DEFCMPLXCMPOP_OP (eq, complex, scalar, ==)
00073 DEFCMPLXCMPOP_OP (ge, complex, scalar, >=)
00074 DEFCMPLXCMPOP_OP (gt, complex, scalar, >)
00075 DEFCMPLXCMPOP_OP (ne, complex, scalar, !=)
00076 
00077 DEFBINOP_OP (el_mul, complex, scalar, *)
00078 
00079 DEFBINOP (el_div, complex, scalar)
00080 {
00081   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00082 
00083   double d = v2.double_value ();
00084 
00085   if (d == 0.0)
00086     gripe_divide_by_zero ();
00087 
00088   return octave_value (v1.complex_value () / d);
00089 }
00090 
00091 DEFBINOP_FN (el_pow, complex, scalar, xpow)
00092 
00093 DEFBINOP (el_ldiv, complex, scalar)
00094 {
00095   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00096 
00097   Complex d = v1.complex_value ();
00098 
00099   if (d == 0.0)
00100     gripe_divide_by_zero ();
00101 
00102   return octave_value (v2.double_value () / d);
00103 }
00104 
00105 DEFBINOP (el_and, complex, scalar)
00106 {
00107   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00108 
00109   return v1.complex_value () != 0.0 && v2.double_value ();
00110 }
00111 
00112 DEFBINOP (el_or, complex, scalar)
00113 {
00114   CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
00115 
00116   return v1.complex_value () != 0.0 || v2.double_value ();
00117 }
00118 
00119 DEFNDCATOP_FN (cs_s, complex, scalar, complex_array, array, concat)
00120 
00121 void
00122 install_cs_s_ops (void)
00123 {
00124   INSTALL_BINOP (op_add, octave_complex, octave_scalar, add);
00125   INSTALL_BINOP (op_sub, octave_complex, octave_scalar, sub);
00126   INSTALL_BINOP (op_mul, octave_complex, octave_scalar, mul);
00127   INSTALL_BINOP (op_div, octave_complex, octave_scalar, div);
00128   INSTALL_BINOP (op_pow, octave_complex, octave_scalar, pow);
00129   INSTALL_BINOP (op_ldiv, octave_complex, octave_scalar, ldiv);
00130   INSTALL_BINOP (op_lt, octave_complex, octave_scalar, lt);
00131   INSTALL_BINOP (op_le, octave_complex, octave_scalar, le);
00132   INSTALL_BINOP (op_eq, octave_complex, octave_scalar, eq);
00133   INSTALL_BINOP (op_ge, octave_complex, octave_scalar, ge);
00134   INSTALL_BINOP (op_gt, octave_complex, octave_scalar, gt);
00135   INSTALL_BINOP (op_ne, octave_complex, octave_scalar, ne);
00136   INSTALL_BINOP (op_el_mul, octave_complex, octave_scalar, el_mul);
00137   INSTALL_BINOP (op_el_div, octave_complex, octave_scalar, el_div);
00138   INSTALL_BINOP (op_el_pow, octave_complex, octave_scalar, el_pow);
00139   INSTALL_BINOP (op_el_ldiv, octave_complex, octave_scalar, el_ldiv);
00140   INSTALL_BINOP (op_el_and, octave_complex, octave_scalar, el_and);
00141   INSTALL_BINOP (op_el_or, octave_complex, octave_scalar, el_or);
00142 
00143   INSTALL_CATOP (octave_complex, octave_scalar, cs_s);
00144 
00145   INSTALL_ASSIGNCONV (octave_complex, octave_scalar, octave_complex_matrix);
00146 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines