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);
376 bool positive = (x < 0) == (y < 0);
379 uint64_t ux = usx >> 32;
380 uint64_t uy = usy >> 32;
388 uint64_t ly =
static_cast<uint32_t
> (usy);
389 uint64_t uxly = ux*ly;
393 uint64_t lx =
static_cast<uint32_t
> (usx);
394 uint64_t lxly = lx*ly;
402 uint64_t lx =
static_cast<uint32_t
> (usx);
403 uint64_t uylx = uy*lx;
407 uint64_t ly =
static_cast<uint32_t
> (usy);
408 uint64_t lylx = ly*lx;
415 uint64_t lx =
static_cast<uint32_t
> (usx);
416 uint64_t ly =
static_cast<uint32_t
> (usy);
422 if (res > static_cast<uint64_t> (max_val ()))
427 return static_cast<int64_t
> (res);
431 if (res > static_cast<uint64_t> (-min_val ()))
436 return -
static_cast<int64_t
> (res);
440 return positive ? max_val () : min_val ();
444 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \
446 OCTAVE_API octave_ ## SUFFIX \
447 operator OP (const octave_ ## SUFFIX & x, const double& y)
449 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \
451 OCTAVE_API octave_ ## SUFFIX \
452 operator OP (const double& x, const octave_ ## SUFFIX & y)
476 octave_int64 y2 (
y / 2);
477 return (
x + y2) + y2;
500 const double p2_64 =
std::pow (2.0, 64);
503 const uint64_t p2_64my = (~
y.value ()) + 1;
545 uint64_t lx =
static_cast<uint32_t
> (
x);
546 uint64_t ux = x >> 32;
547 uint64_t ly =
static_cast<uint32_t
> (
y);
548 uint64_t uy = y >> 32;
549 uint64_t
a = lx * ly;
551 uint64_t uxly = ux*ly;
552 uint64_t uylx = uy*lx;
553 a +=
static_cast<uint32_t
> (uxly); uxly >>= 32;
554 a +=
static_cast<uint32_t
> (uylx); uylx >>= 32;
556 uint64_t uxuy = ux * uy;
557 a += uxly; a += uylx; a += uxuy;
566 sign = x < 0; x = fabs (x);
569 mtis =
static_cast<uint64_t
> (ldexp (x, 52));
577 double x = ldexp (static_cast<double> (mtis), exp);
578 return sign ? -x :
x;
604 for (
short i = 0;
i < 4;
i++)
622 else if (fabs (
y) == 0.5)
637 sign = (sign != (
x.value () < 0));
640 for (
short i = 0;
i < 4;
i++)
682 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \
683 template OCTAVE_API bool \
684 octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
686 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
687 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \
688 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \
689 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \
690 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double)
701 template <
typename T>
710 if (b == zero || a == one)
715 retval = (b.
value () % 2) ? a : one;
731 retval = retval * a_val;
736 a_val = a_val * a_val;
743 template <
typename T>
748 template <
typename T>
752 return ((b >= 0 && b < std::numeric_limits<T>::digits
758 template <
typename T>
763 template <
typename T>
767 return ((b >= 0 && b < std::numeric_limits<T>::digits
776 template <
typename T>
781 template <
typename T>
785 return ((b >= 0 && b < std::numeric_limits<T>::digits
791 #define INSTANTIATE_INTTYPE(T) \
792 template class OCTAVE_API octave_int<T>; \
793 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \
794 template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \
795 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \
796 template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \
797 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \
798 template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \
799 template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \
800 template OCTAVE_API octave_int<T> \
801 bitshift (const octave_int<T>&, int, const octave_int<T>&);
octave_int< uint64_t > octave_uint64
static const octave_int one
OCTAVE_EXPORT octave_value_list uint16
#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)
void octave_end_long_double_rounding(unsigned int oldcw)
float float_value(void) const
double frexp(double x, int *expptr)
double double_value(void) const
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)
OCTAVE_EXPORT octave_value_list uint32
std::complex< double > w(std::complex< double > z, double relerr=0)
OCTAVE_EXPORT octave_value_list int16
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
OCTAVE_EXPORT octave_value_list int32
static OCTAVE_API bool emulate_mop(double, int64_t)
#define DEFINE_REVERTED_OPERATOR(OP1, OP2)
static octave_int< T > max(void)
static const octave_int zero
OCTAVE_EXPORT octave_value_list int64
charNDArray max(char d, const charNDArray &m)
=val(i)}if ode{val(i)}occurs in table i
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
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)
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 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
charNDArray min(char d, const charNDArray &m)