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