GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-s-s.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 
67 
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 
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 
102 
103 DEFBINOP_OP (el_mul, scalar, scalar, *)
104 
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 
135 
137 
138 void
139 install_s_s_ops (octave::type_info& ti)
140 {
142  INSTALL_UNOP_TI (ti, op_uplus, octave_scalar, uplus);
143  INSTALL_UNOP_TI (ti, op_uminus, octave_scalar, uminus);
145  INSTALL_UNOP_TI (ti, op_hermitian, octave_scalar, hermitian);
146 
147  INSTALL_NCUNOP_TI (ti, op_incr, octave_scalar, incr);
148  INSTALL_NCUNOP_TI (ti, op_decr, octave_scalar, decr);
149 
168 
170 
174 
178 }
octave_value xpow(const SparseMatrix &a, double b)
Definition: sparse-xpow.cc:58
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1574
#define DEFBINOP(name, t1, t2)
Definition: ops.h:264
#define DEFUNOP(name, t)
Definition: ops.h:213
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1620
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:53
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1613
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5264
double scalar_value(bool=false) const
Definition: ov-scalar.h:148
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1621
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:386
bool isnan(bool)
Definition: lo-mappers.h:187
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1608
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:49
#define DEFUNOP_OP(name, t, op)
Definition: ops.h:217
void err_nan_to_logical_conversion(void)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:269
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:400
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:45
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1606
then the function must return scalars which will be concatenated into the return array(s). If code
Definition: cellfun.cc:400
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1623
double double_value(bool=false) const
Definition: ov-scalar.h:143
octave_value op_not(const octave_value &a)
Definition: ov.h:1573
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:58
void install_s_s_ops(octave::type_info &ti)
Definition: op-s-s.cc:139
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1622
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
double double_value(bool=false) const
Definition: ov-ch-mat.cc:66
void warn_divide_by_zero(void)
Definition: errwarn.cc:326
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1612
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1611
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1619
#define DEFSCALARBOOLOP_OP(name, t1, t2, op)
Definition: ops.h:295
#define INSTALL_ASSIGNCONV_TI(ti, t1, t2, tr)
Definition: ops.h:71
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1616
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1603
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1609
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1604
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1618
#define DEFBINOP_FN(name, t1, t2, f)
Definition: ops.h:324
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1614
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:382
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1575
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1605
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1615
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:251