SourceForge has been redesigned. Learn more.
Close

[6164d0]: / src / op-mp.cc  Maximize  Restore  History

Download this file

184 lines (152 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright (C) 2014 Pascal Dupuis <cdemills@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
#include <octave/config.h>
#include <octave/ov-scalar.h>
#include <octave/ov-complex.h>
#include <octave/ov-re-mat.h>
#include <octave/ov-cx-mat.h>
#include <octave/oct-obj.h>
#include <octave/ops.h>
#include "ov-mp.h"
#include "op-mp.h"
DEFUNOP_OP (transpose, mp, /* no-op */)
DEFUNOP_OP (hermitian, mp, /* no-op */)
/* generate our own version of DEFUNOP_OP */
#ifdef DEFUNOP_OP
#undef DEFUNOP_OP
#endif
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ /* provides some uninitialized context */ \
octave_mp retval; \
return retval.oct_monop_proxy (a, mpfr_ ## op); \
}
DEFUNOP_OP (uminus, octave_mp, neg)
#undef DEFUNOP_OP
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ /* provides some uninitialized context */ \
octave_mp retval; \
return retval.oct_monocmp_proxy (a, mpfr_ ## op).bool_value (); \
}
DEFUNOP_OP (not, octave_mp, zero_p)
/*
%!assert(!mpv(4)==0)
%!assert(!mpv(0)==1)
%!assert(-mpv(-4)==4)
*/
/* generate our own version of DEFBINOP */
#if defined(DEFBINOP_OP)
#undef DEFBINOP_OP
#endif
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
octave_mp retval; \
return retval.oct_binop_proxy (a1, a2, mpfr_ ## op); \
}
DEFBINOP_OP (add, mp, mp, add)
DEFBINOP_OP (sub, mp, mp, sub)
DEFBINOP_OP (mul, mp, mp, mul)
DEFBINOP_OP (div, mp, mp, div)
DEFBINOP_OP (pow, mp, mp, pow)
/* ldiv is div with inverted args */
#undef DEFBINOP_OP
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
octave_mp retval; \
return retval.oct_binop_proxy (a2, a1, mpfr_ ## op); \
}
DEFBINOP_OP (ldiv, mp, mp, div)
#undef DEFBINOP_OP
/* For the comparisons functions */
#undef DEFBINOP_OP
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
octave_mp retval; \
return retval.oct_bincmp_proxy (a1, a2, mpfr_ ## op); \
}
DEFBINOP_OP (lt, mp, mp, less_p)
DEFBINOP_OP (le, mp, mp, lessequal_p)
DEFBINOP_OP (eq, mp, mp, equal_p)
DEFBINOP_OP (gt, mp, mp, greater_p)
DEFBINOP_OP (ge, mp, mp, greaterequal_p)
DEFBINOP_OP (ne, mp, mp, lessgreater_p)
// DEFBINOP_OP (el_and, mp, mp, &&)
//DEFBINOP_OP (el_or, mp, mp, ||)
//#include "op-mp.h"
/* definitions for when mp is first */
// DEFINE_EX_MATRIX_OPS(mp, ex_matrix)
// DEFINE_EX_MATRIX_OPS(mp, matrix)
// DEFINE_EX_MATRIX_OPS(mp, complex_matrix)
// DEFINE_EX_EX_OPS(mp, scalar)
// DEFINE_EX_EX_OPS(mp, complex)
// DEFINE_EX_EX_OPS(mp, mp)
// DEFINE_EX_EX_OPS(mp, ex)
/* extra operators need for octave builtin types */
//DEFINE_MATRIX_EX_OPS(complex_matrix, mp)
//DEFINE_MATRIX_EX_OPS(matrix, mp)
//DEFINE_EX_EX_OPS(scalar, mp)
//DEFINE_EX_EX_OPS(complex, mp)
void install_mp_ops()
{
INSTALL_UNOP (op_not, octave_mp, not);
INSTALL_UNOP (op_uminus, octave_mp, uminus);
INSTALL_UNOP (op_transpose, octave_mp, transpose);
INSTALL_UNOP (op_hermitian, octave_mp, hermitian);
INSTALL_NCUNOP (op_incr, octave_mp, s_incr);
INSTALL_NCUNOP (op_decr, octave_mp, s_decr);
// INSTALL_BINOP (op_eq, octave_mp, octave_mp, eq);
// INSTALL_BINOP (op_ne, octave_mp, octave_mp, ne);
// INSTALL_BINOP (op_el_and, octave_mp, octave_mp, el_and);
// INSTALL_BINOP (op_el_or, octave_mp, octave_mp, el_or);
INSTALL_BINOP (op_add, octave_mp, octave_mp, add);
INSTALL_BINOP (op_add, octave_scalar, octave_mp, add);
INSTALL_BINOP (op_add, octave_mp, octave_scalar, add);
INSTALL_BINOP (op_sub, octave_mp, octave_mp, sub);
INSTALL_BINOP (op_sub, octave_scalar, octave_mp, sub);
INSTALL_BINOP (op_sub, octave_mp, octave_scalar, sub);
INSTALL_BINOP (op_mul, octave_mp, octave_mp, mul);
INSTALL_BINOP (op_mul, octave_scalar, octave_mp, mul);
INSTALL_BINOP (op_mul, octave_mp, octave_scalar, mul);
INSTALL_BINOP (op_div, octave_mp, octave_mp, div);
INSTALL_BINOP (op_div, octave_scalar, octave_mp, div);
INSTALL_BINOP (op_div, octave_mp, octave_scalar, div);
INSTALL_BINOP (op_ldiv, octave_mp, octave_mp, ldiv);
INSTALL_BINOP (op_ldiv, octave_scalar, octave_mp, ldiv);
INSTALL_BINOP (op_ldiv, octave_mp, octave_scalar, ldiv);
INSTALL_BINOP (op_pow, octave_mp, octave_mp, pow);
INSTALL_BINOP (op_pow, octave_scalar, octave_mp, pow);
INSTALL_BINOP (op_pow, octave_mp, octave_scalar, pow);
INSTALL_BINOP (op_lt, octave_mp, octave_mp, lt);
INSTALL_BINOP (op_lt, octave_scalar, octave_mp, lt);
INSTALL_BINOP (op_lt, octave_mp, octave_scalar, lt);
INSTALL_BINOP (op_le, octave_mp, octave_mp, le);
INSTALL_BINOP (op_le, octave_scalar, octave_mp, le);
INSTALL_BINOP (op_le, octave_mp, octave_scalar, le);
INSTALL_BINOP (op_eq, octave_mp, octave_mp, eq);
INSTALL_BINOP (op_eq, octave_scalar, octave_mp, eq);
INSTALL_BINOP (op_eq, octave_mp, octave_scalar, eq);
INSTALL_BINOP (op_gt, octave_mp, octave_mp, gt);
INSTALL_BINOP (op_gt, octave_scalar, octave_mp, gt);
INSTALL_BINOP (op_gt, octave_mp, octave_scalar, gt);
INSTALL_BINOP (op_ge, octave_mp, octave_mp, ge);
INSTALL_BINOP (op_ge, octave_scalar, octave_mp, ge);
INSTALL_BINOP (op_ge, octave_mp, octave_scalar, ge);
INSTALL_BINOP (op_ne, octave_mp, octave_mp, ne);
INSTALL_BINOP (op_ne, octave_scalar, octave_mp, ne);
INSTALL_BINOP (op_ne, octave_mp, octave_scalar, ne);
}