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