GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
op-s-s.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "Array-util.h"
28 
29 #include "errwarn.h"
30 #include "ovl.h"
31 #include "ov.h"
32 #include "ov-scalar.h"
33 #include "ov-float.h"
34 #include "ov-re-mat.h"
35 #include "ov-flt-re-mat.h"
36 #include "ov-typeinfo.h"
37 #include "ov-null-mat.h"
38 #include "ops.h"
39 #include "xdiv.h"
40 #include "xpow.h"
41 
42 // scalar unary ops.
43 
45 {
46  const octave_scalar& v = dynamic_cast<const octave_scalar&> (a);
47  double x = v.scalar_value ();
48  if (octave::math::isnan (x))
50 
51  return octave_value (x == 0.0);
52 }
53 
54 DEFUNOP_OP (uplus, scalar, /* no-op */)
55 DEFUNOP_OP (uminus, scalar, -)
56 DEFUNOP_OP (transpose, scalar, /* no-op */)
57 DEFUNOP_OP (hermitian, scalar, /* no-op */)
58 
59 DEFNCUNOP_METHOD (incr, scalar, increment)
60 DEFNCUNOP_METHOD (decr, scalar, decrement)
61 
62 // scalar by scalar ops.
63 
64 DEFBINOP_OP (add, scalar, scalar, +)
65 DEFBINOP_OP (sub, scalar, scalar, -)
66 DEFBINOP_OP (mul, scalar, scalar, *)
67 
68 DEFBINOP (div, scalar, scalar)
69 {
70  const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1);
71  const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2);
72 
73  double d = v2.double_value ();
74 
75  if (d == 0.0)
77 
78  return octave_value (v1.double_value () / d);
79 }
80 
82 
83 DEFBINOP (ldiv, scalar, scalar)
84 {
85  const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1);
86  const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2);
87 
88  double d = v1.double_value ();
89 
90  if (d == 0.0)
92 
93  return octave_value (v2.double_value () / d);
94 }
95 
97 DEFBINOP_OP (le, scalar, scalar, <=)
98 DEFBINOP_OP (eq, scalar, scalar, ==)
99 DEFBINOP_OP (ge, scalar, scalar, >=)
100 DEFBINOP_OP (gt, scalar, scalar, >)
101 DEFBINOP_OP (ne, scalar, scalar, !=)
102 
103 DEFBINOP_OP (el_mul, scalar, scalar, *)
104 
105 DEFBINOP (el_div, scalar, scalar)
106 {
107  const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1);
108  const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2);
109 
110  double d = v2.double_value ();
111 
112  if (d == 0.0)
114 
115  return octave_value (v1.double_value () / d);
116 }
117 
119 
120 DEFBINOP (el_ldiv, scalar, scalar)
121 {
122  const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1);
123  const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2);
124 
125  double d = v1.double_value ();
126 
127  if (d == 0.0)
129 
130  return octave_value (v2.double_value () / d);
131 }
132 
134 DEFSCALARBOOLOP_OP (el_or, scalar, scalar, ||)
135 
136 DEFNDCATOP_FN (s_s, scalar, scalar, array, array, concat)
137 
138 void
140 {
146 
147  INSTALL_NCUNOP (op_incr, octave_scalar, incr);
148  INSTALL_NCUNOP (op_decr, octave_scalar, decr);
149 
168 
170 
173 
177 }
octave_value xpow(const SparseMatrix &a, double b)
Definition: sparse-xpow.cc:58
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1485
#define DEFBINOP(name, t1, t2)
Definition: ops.h:223
#define DEFUNOP(name, t)
Definition: ops.h:172
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1531
#define INSTALL_NCUNOP(op, t, f)
Definition: ops.h:44
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1524
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5342
double scalar_value(bool=false) const
Definition: ov-scalar.h:150
void install_s_s_ops(void)
Definition: op-s-s.cc:139
bool isnan(double x)
Definition: lo-mappers.cc:347
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1532
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:382
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:655
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1519
#define DEFUNOP_OP(name, t, op)
Definition: ops.h:176
void err_nan_to_logical_conversion(void)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:228
const octave_base_value & a2
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1517
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1534
#define INSTALL_BINOP(op, t1, t2, f)
Definition: ops.h:48
octave_value op_not(const octave_value &a)
Definition: ov.h:1484
then the function must return scalars which will be concatenated into the return array(s).If code
Definition: cellfun.cc:398
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1488
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1533
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
void warn_divide_by_zero(void)
Definition: errwarn.cc:320
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1523
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1522
#define INSTALL_CATOP(t1, t2, f)
Definition: ops.h:53
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1530
#define DEFSCALARBOOLOP_OP(name, t1, t2, op)
Definition: ops.h:254
double double_value(bool=false) const
Definition: ov-scalar.h:145
const octave_char_matrix & v2
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1527
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1514
#define INSTALL_UNOP(op, t, f)
Definition: ops.h:40
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1520
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1515
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1529
#define DEFBINOP_FN(name, t1, t2, f)
Definition: ops.h:283
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1489
#define INSTALL_ASSIGNCONV(t1, t2, tr)
Definition: ops.h:66
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1525
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:341
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1486
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1516
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1526
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:210