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