op-s-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 "Array-util.h"
00028 
00029 #include "gripes.h"
00030 #include "oct-obj.h"
00031 #include "ov.h"
00032 #include "ov-scalar.h"
00033 #include "ov-float.h"
00034 #include "ov-re-mat.h"
00035 #include "ov-flt-re-mat.h"
00036 #include "ov-typeinfo.h"
00037 #include "ov-null-mat.h"
00038 #include "ops.h"
00039 #include "xdiv.h"
00040 #include "xpow.h"
00041 
00042 // scalar unary ops.
00043 
00044 DEFUNOP (not, scalar)
00045 {
00046   CAST_UNOP_ARG (const octave_scalar&);
00047   double x = v.scalar_value ();
00048   if (xisnan (x))
00049     gripe_nan_to_logical_conversion ();
00050   return octave_value (x == 0.0);
00051 }
00052 
00053 DEFUNOP_OP (uplus, scalar, /* no-op */)
00054 DEFUNOP_OP (uminus, scalar, -)
00055 DEFUNOP_OP (transpose, scalar, /* no-op */)
00056 DEFUNOP_OP (hermitian, scalar, /* no-op */)
00057 
00058 DEFNCUNOP_METHOD (incr, scalar, increment)
00059 DEFNCUNOP_METHOD (decr, scalar, decrement)
00060 
00061 // scalar by scalar ops.
00062 
00063 DEFBINOP_OP (add, scalar, scalar, +)
00064 DEFBINOP_OP (sub, scalar, scalar, -)
00065 DEFBINOP_OP (mul, scalar, scalar, *)
00066 
00067 DEFBINOP (div, scalar, scalar)
00068 {
00069   CAST_BINOP_ARGS (const octave_scalar&, const octave_scalar&);
00070 
00071   double d = v2.double_value ();
00072 
00073   if (d == 0.0)
00074     gripe_divide_by_zero ();
00075 
00076   return octave_value (v1.double_value () / d);
00077 }
00078 
00079 DEFBINOP_FN (pow, scalar, scalar, xpow)
00080 
00081 DEFBINOP (ldiv, scalar, scalar)
00082 {
00083   CAST_BINOP_ARGS (const octave_scalar&, const octave_scalar&);
00084 
00085   double d = v1.double_value ();
00086 
00087   if (d == 0.0)
00088     gripe_divide_by_zero ();
00089 
00090   return octave_value (v2.double_value () / d);
00091 }
00092 
00093 DEFBINOP_OP (lt, scalar, scalar, <)
00094 DEFBINOP_OP (le, scalar, scalar, <=)
00095 DEFBINOP_OP (eq, scalar, scalar, ==)
00096 DEFBINOP_OP (ge, scalar, scalar, >=)
00097 DEFBINOP_OP (gt, scalar, scalar, >)
00098 DEFBINOP_OP (ne, scalar, scalar, !=)
00099 
00100 DEFBINOP_OP (el_mul, scalar, scalar, *)
00101 
00102 DEFBINOP (el_div, scalar, scalar)
00103 {
00104   CAST_BINOP_ARGS (const octave_scalar&, const octave_scalar&);
00105 
00106   double d = v2.double_value ();
00107 
00108   if (d == 0.0)
00109     gripe_divide_by_zero ();
00110 
00111   return octave_value (v1.double_value () / d);
00112 }
00113 
00114 DEFBINOP_FN (el_pow, scalar, scalar, xpow)
00115 
00116 DEFBINOP (el_ldiv, scalar, scalar)
00117 {
00118   CAST_BINOP_ARGS (const octave_scalar&, const octave_scalar&);
00119 
00120   double d = v1.double_value ();
00121 
00122   if (d == 0.0)
00123     gripe_divide_by_zero ();
00124 
00125   return octave_value (v2.double_value () / d);
00126 }
00127 
00128 DEFSCALARBOOLOP_OP (el_and, scalar, scalar, &&)
00129 DEFSCALARBOOLOP_OP (el_or, scalar, scalar, ||)
00130 
00131 DEFNDCATOP_FN (s_s, scalar, scalar, array, array, concat)
00132 
00133 void
00134 install_s_s_ops (void)
00135 {
00136   INSTALL_UNOP (op_not, octave_scalar, not);
00137   INSTALL_UNOP (op_uplus, octave_scalar, uplus);
00138   INSTALL_UNOP (op_uminus, octave_scalar, uminus);
00139   INSTALL_UNOP (op_transpose, octave_scalar, transpose);
00140   INSTALL_UNOP (op_hermitian, octave_scalar, hermitian);
00141 
00142   INSTALL_NCUNOP (op_incr, octave_scalar, incr);
00143   INSTALL_NCUNOP (op_decr, octave_scalar, decr);
00144 
00145   INSTALL_BINOP (op_add, octave_scalar, octave_scalar, add);
00146   INSTALL_BINOP (op_sub, octave_scalar, octave_scalar, sub);
00147   INSTALL_BINOP (op_mul, octave_scalar, octave_scalar, mul);
00148   INSTALL_BINOP (op_div, octave_scalar, octave_scalar, div);
00149   INSTALL_BINOP (op_pow, octave_scalar, octave_scalar, pow);
00150   INSTALL_BINOP (op_ldiv, octave_scalar, octave_scalar, ldiv);
00151   INSTALL_BINOP (op_lt, octave_scalar, octave_scalar, lt);
00152   INSTALL_BINOP (op_le, octave_scalar, octave_scalar, le);
00153   INSTALL_BINOP (op_eq, octave_scalar, octave_scalar, eq);
00154   INSTALL_BINOP (op_ge, octave_scalar, octave_scalar, ge);
00155   INSTALL_BINOP (op_gt, octave_scalar, octave_scalar, gt);
00156   INSTALL_BINOP (op_ne, octave_scalar, octave_scalar, ne);
00157   INSTALL_BINOP (op_el_mul, octave_scalar, octave_scalar, el_mul);
00158   INSTALL_BINOP (op_el_div, octave_scalar, octave_scalar, el_div);
00159   INSTALL_BINOP (op_el_pow, octave_scalar, octave_scalar, el_pow);
00160   INSTALL_BINOP (op_el_ldiv, octave_scalar, octave_scalar, el_ldiv);
00161   INSTALL_BINOP (op_el_and, octave_scalar, octave_scalar, el_and);
00162   INSTALL_BINOP (op_el_or, octave_scalar, octave_scalar, el_or);
00163 
00164   INSTALL_CATOP (octave_scalar, octave_scalar, s_s);
00165 
00166   INSTALL_ASSIGNCONV (octave_scalar, octave_scalar, octave_matrix);
00167   INSTALL_ASSIGNCONV (octave_float_scalar, octave_scalar, octave_float_matrix);
00168 
00169   INSTALL_ASSIGNCONV (octave_scalar, octave_null_matrix, octave_matrix);
00170   INSTALL_ASSIGNCONV (octave_scalar, octave_null_str, octave_matrix);
00171   INSTALL_ASSIGNCONV (octave_scalar, octave_null_sq_str, octave_matrix);
00172 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines