24 #if defined (HAVE_CONFIG_H) 39 #define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \ 41 OCTAVE_API const char * \ 42 octave_int<TYPE>::type_name () { return TYPENAME; } 65 return static_cast<T
> (0);
67 else if (
value < thmin)
71 else if (
value > thmax)
78 return static_cast<T
> (rvalue);
82 #define INSTANTIATE_CONVERT_REAL_1(T, S) \ 86 octave_int_base<T>::convert_real (const S&) 88 #define INSTANTIATE_CONVERT_REAL(S) \ 89 INSTANTIATE_CONVERT_REAL_1 (int8_t, S); \ 90 INSTANTIATE_CONVERT_REAL_1 (uint8_t, S); \ 91 INSTANTIATE_CONVERT_REAL_1 (int16_t, S); \ 92 INSTANTIATE_CONVERT_REAL_1 (uint16_t, S); \ 93 INSTANTIATE_CONVERT_REAL_1 (int32_t, S); \ 94 INSTANTIATE_CONVERT_REAL_1 (uint32_t, S); \ 95 INSTANTIATE_CONVERT_REAL_1 (int64_t, S); \ 96 INSTANTIATE_CONVERT_REAL_1 (uint64_t, S) 100 #if defined (OCTAVE_INT_USE_LONG_DOUBLE) 104 #if defined (OCTAVE_INT_USE_LONG_DOUBLE) 106 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED) 108 #define DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES(T) \ 109 template <typename xop> \ 111 octave_int_cmp_op::external_mop (double x, T y) \ 113 unsigned int oldcw = octave_begin_long_double_rounding (); \ 115 bool retval = xop::op (static_cast<long double> (x), \ 116 static_cast<long double> (y)); \ 118 octave_end_long_double_rounding (oldcw); \ 123 template <typename xop> \ 125 octave_int_cmp_op::external_mop (T x, double y) \ 127 unsigned int oldcw = octave_begin_long_double_rounding (); \ 129 bool retval = xop::op (static_cast<long double> (x), \ 130 static_cast<long double> (y)); \ 132 octave_end_long_double_rounding (oldcw); \ 137 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t)
138 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (uint64_t)
140 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP(OP, T) \ 141 template OCTAVE_API bool \ 142 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (double, T); \ 143 template OCTAVE_API bool \ 144 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (T, double) 146 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS(T) \ 147 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (lt, T); \ 148 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (le, T); \ 149 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (gt, T); \ 150 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ge, T); \ 151 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (eq, T); \ 152 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ne, T) 154 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (int64_t);
155 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (uint64_t);
158 octave_external_uint64_uint64_mul (uint64_t
x, uint64_t
y)
170 octave_external_int64_int64_mul (int64_t
x, int64_t
y)
189 #define OCTAVE_LONG_DOUBLE_OP(T, OP, NAME) \ 191 external_double_ ## T ## _ ## NAME (double x, T y) \ 193 unsigned int oldcw = octave_begin_long_double_rounding (); \ 195 T retval = T (x OP static_cast<long double> (y.value ())); \ 197 octave_end_long_double_rounding (oldcw); \ 203 external_ ## T ## _double_ ## NAME (T x, double y) \ 205 unsigned int oldcw = octave_begin_long_double_rounding (); \ 207 T retval = T (static_cast<long double> (x.value ()) OP y); \ 209 octave_end_long_double_rounding (oldcw); \ 214 #define OCTAVE_LONG_DOUBLE_OPS(T) \ 215 OCTAVE_LONG_DOUBLE_OP (T, +, add); \ 216 OCTAVE_LONG_DOUBLE_OP (T, -, sub); \ 217 OCTAVE_LONG_DOUBLE_OP (T, *, mul); \ 218 OCTAVE_LONG_DOUBLE_OP (T, /, div) 229 template <
typename xop>
238 return xop::op (xx,
y);
245 return xop::op (
x, static_cast<uint64_t> (xx));
249 template <
typename xop>
259 return xop::op (xx,
y);
268 return xop::op (
x, static_cast<int64_t> (xx));
276 template <
typename xop>
283 #define DEFINE_REVERTED_OPERATOR(OP1,OP2) \ 285 class rev_op<octave_int_cmp_op::OP1> \ 288 typedef octave_int_cmp_op::OP2 op; \ 296 template <
typename xop>
301 return mop<rop> (
y,
x);
304 template <
typename xop>
309 return mop<rop> (
y,
x);
319 uint64_t ux =
x >> 32;
320 uint64_t uy =
y >> 32;
328 uint64_t ly =
static_cast<uint32_t
> (
y);
329 uint64_t uxly = ux*ly;
333 uint64_t lx =
static_cast<uint32_t
> (
x);
334 uint64_t lxly = lx*ly;
335 res = add (uxly, lxly);
340 uint64_t lx =
static_cast<uint32_t
> (
x);
341 uint64_t uylx = uy*lx;
345 uint64_t ly =
static_cast<uint32_t
> (
y);
346 uint64_t lylx = ly*lx;
347 res = add (uylx, lylx);
351 uint64_t lx =
static_cast<uint32_t
> (
x);
352 uint64_t ly =
static_cast<uint32_t
> (
y);
375 bool positive = (
x < 0) == (
y < 0);
378 uint64_t ux = usx >> 32;
379 uint64_t uy = usy >> 32;
387 uint64_t ly =
static_cast<uint32_t
> (usy);
388 uint64_t uxly = ux*ly;
392 uint64_t lx =
static_cast<uint32_t
> (usx);
393 uint64_t lxly = lx*ly;
401 uint64_t lx =
static_cast<uint32_t
> (usx);
402 uint64_t uylx = uy*lx;
406 uint64_t ly =
static_cast<uint32_t
> (usy);
407 uint64_t lylx = ly*lx;
414 uint64_t lx =
static_cast<uint32_t
> (usx);
415 uint64_t ly =
static_cast<uint32_t
> (usy);
421 if (res > static_cast<uint64_t> (max_val ()))
424 return static_cast<int64_t
> (res);
428 if (res > static_cast<uint64_t> (min_val ()))
431 return -
static_cast<int64_t
> (res);
435 return positive ? max_val () : min_val ();
439 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \ 441 OCTAVE_API octave_ ## SUFFIX \ 442 operator OP (const octave_ ## SUFFIX & x, const double& y) 444 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \ 446 OCTAVE_API octave_ ## SUFFIX \ 447 operator OP (const double& x, const octave_ ## SUFFIX & y) 472 return (
x + y2) + y2;
495 const double p2_64 =
std::pow (2.0, 64);
498 const uint64_t p2_64my = (~
y.value ()) + 1;
540 uint64_t lx =
static_cast<uint32_t
> (
x);
541 uint64_t ux =
x >> 32;
542 uint64_t ly =
static_cast<uint32_t
> (
y);
543 uint64_t uy =
y >> 32;
544 uint64_t
a = lx * ly;
546 uint64_t uxly = ux*ly;
547 uint64_t uylx = uy*lx;
548 a +=
static_cast<uint32_t
> (uxly); uxly >>= 32;
549 a +=
static_cast<uint32_t
> (uylx); uylx >>= 32;
551 uint64_t uxuy = ux * uy;
552 a += uxly;
a += uylx;
a += uxuy;
561 sign =
x < 0;
x = fabs (
x);
564 mtis =
static_cast<uint64_t
> (ldexp (
x, 52));
572 double x = ldexp (static_cast<double> (mtis), exp);
573 return sign ? -
x :
x;
599 for (
short i = 0;
i < 4;
i++)
617 else if (fabs (
y) == 0.5)
632 sign = (sign != (
x.value () < 0));
635 for (
short i = 0;
i < 4;
i++)
677 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \ 678 template OCTAVE_API bool \ 679 octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y) 681 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \ 682 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \ 683 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \ 684 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \ 685 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double) 696 template <
typename T>
705 if (
b ==
zero ||
a == one)
710 retval = (
b.value () % 2) ?
a : one;
731 a_val = a_val * a_val;
738 template <
typename T>
743 template <
typename T>
747 return ((
b >= 0 &&
b < std::numeric_limits<T>::digits
753 template <
typename T>
758 template <
typename T>
762 return ((
b >= 0 &&
b < std::numeric_limits<T>::digits
766 static_cast<double> (
b))));
771 template <
typename T>
776 template <
typename T>
780 return ((
b >= 0 &&
b < std::numeric_limits<T>::digits
784 static_cast<double> (
b))));
787 #define INSTANTIATE_INTTYPE(T) \ 788 template class OCTAVE_API octave_int<T>; \ 789 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \ 790 template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \ 791 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \ 792 template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \ 793 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \ 794 template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \ 795 template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \ 796 template OCTAVE_API octave_int<T> \ 797 bitshift (const octave_int<T>&, int, const octave_int<T>&); octave_int< uint64_t > octave_uint64
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by zero($0/0$)
#define INSTANTIATE_CONVERT_REAL(S)
static void umul128(uint64_t x, uint64_t y, uint32_t w[4])
#define DOUBLE_INT_BINOP_DECL(OP, SUFFIX)
#define INT_DOUBLE_BINOP_DECL(OP, SUFFIX)
static const octave_int one
void octave_end_long_double_rounding(unsigned int oldcw)
double frexp(double x, int *expptr)
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
#define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP)
octave_int< T > powf(const float &a, const octave_int< T > &b)
static S compute_threshold(S val, T orig_val)
std::complex< double > w(std::complex< double > z, double relerr=0)
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
static octave_int< T > max(void)
static OCTAVE_API bool emulate_mop(double, int64_t)
#define DEFINE_REVERTED_OPERATOR(OP1, OP2)
charNDArray max(char d, const charNDArray &m)
static const octave_int zero
octave_int< int64_t > octave_int64
the element is set to zero In other the statement xample y
static double dbleget(bool sign, uint32_t mtis, int exp)
#define INSTANTIATE_INTTYPE(T)
static void dblesplit(double x, bool &sign, uint64_t &mtis, int &exp)
static T convert_real(const S &value)
nd group nd example For each display the value
uint64_t mul_internal(uint64_t x, uint64_t y)
unsigned int octave_begin_long_double_rounding(void)
#define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME)
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
charNDArray min(char d, const charNDArray &m)