26 #if defined (HAVE_CONFIG_H)
42 #define DEFINE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \
44 OCTAVE_API const char * \
45 octave_int<TYPE>::type_name (void) { return TYPENAME; }
62 static const S thmin = compute_threshold (
static_cast<S
> (min_val ()),
64 static const S thmax = compute_threshold (
static_cast<S
> (max_val ()),
67 return static_cast<T
> (0);
68 else if (value < thmin)
70 else if (value > thmax)
75 return static_cast<T
> (rvalue);
79 #define INSTANTIATE_CONVERT_REAL_1(T, S) \
83 octave_int_base<T>::convert_real (const S&)
85 #define INSTANTIATE_CONVERT_REAL(S) \
86 INSTANTIATE_CONVERT_REAL_1 (int8_t, S); \
87 INSTANTIATE_CONVERT_REAL_1 (uint8_t, S); \
88 INSTANTIATE_CONVERT_REAL_1 (int16_t, S); \
89 INSTANTIATE_CONVERT_REAL_1 (uint16_t, S); \
90 INSTANTIATE_CONVERT_REAL_1 (int32_t, S); \
91 INSTANTIATE_CONVERT_REAL_1 (uint32_t, S); \
92 INSTANTIATE_CONVERT_REAL_1 (int64_t, S); \
93 INSTANTIATE_CONVERT_REAL_1 (uint64_t, S)
97 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
101 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
103 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
105 # define DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES(T) \
106 template <typename xop> \
108 octave_int_cmp_op::external_mop (double x, T y) \
110 unsigned int oldcw = octave_begin_long_double_rounding (); \
112 bool retval = xop::op (static_cast<long double> (x), \
113 static_cast<long double> (y)); \
115 octave_end_long_double_rounding (oldcw); \
120 template <typename xop> \
122 octave_int_cmp_op::external_mop (T x, double y) \
124 unsigned int oldcw = octave_begin_long_double_rounding (); \
126 bool retval = xop::op (static_cast<long double> (x), \
127 static_cast<long double> (y)); \
129 octave_end_long_double_rounding (oldcw); \
134 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t)
135 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (uint64_t)
137 # define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP(OP, T) \
138 template OCTAVE_API bool \
139 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (double, T); \
141 template OCTAVE_API bool \
142 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (T, double)
144 # define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS(T) \
145 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (lt, T); \
146 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (le, T); \
147 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (gt, T); \
148 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ge, T); \
149 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (eq, T); \
150 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ne, T)
152 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (int64_t);
153 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (uint64_t);
156 octave_external_uint64_uint64_mul (uint64_t
x, uint64_t y)
168 octave_external_int64_int64_mul (int64_t
x, int64_t y)
187 # define DEFINE_OCTAVE_LONG_DOUBLE_OP(T, OP, NAME) \
189 external_double_ ## T ## _ ## NAME (double x, T y) \
191 unsigned int oldcw = octave_begin_long_double_rounding (); \
193 T retval = T (x OP static_cast<long double> (y.value ())); \
195 octave_end_long_double_rounding (oldcw); \
201 external_ ## T ## _double_ ## NAME (T x, double y) \
203 unsigned int oldcw = octave_begin_long_double_rounding (); \
205 T retval = T (static_cast<long double> (x.value ()) OP y); \
207 octave_end_long_double_rounding (oldcw); \
212 # define DEFINE_OCTAVE_LONG_DOUBLE_OPS(T) \
213 DEFINE_OCTAVE_LONG_DOUBLE_OP (T, +, add); \
214 DEFINE_OCTAVE_LONG_DOUBLE_OP (T, -, sub); \
215 DEFINE_OCTAVE_LONG_DOUBLE_OP (T, *, mul); \
216 DEFINE_OCTAVE_LONG_DOUBLE_OP (T, /, div)
227 template <
typename xop>
236 return xop::op (xx, y);
243 return xop::op (
x,
static_cast<uint64_t
> (xx));
247 template <
typename xop>
257 return xop::op (xx, y);
266 return xop::op (
x,
static_cast<int64_t
> (xx));
274 template <
typename xop>
281 #define DEFINE_REVERTED_OPERATOR(OP1, OP2) \
283 class rev_op<octave_int_cmp_op::OP1> \
286 typedef octave_int_cmp_op::OP2 op; \
294 template <
typename xop>
299 return mop<rop> (y,
x);
302 template <
typename xop>
307 return mop<rop> (y,
x);
317 uint64_t ux =
x >> 32;
318 uint64_t uy = y >> 32;
326 uint64_t ly =
static_cast<uint32_t
> (y);
327 uint64_t uxly = ux*ly;
331 uint64_t lx =
static_cast<uint32_t
> (
x);
332 uint64_t lxly = lx*ly;
333 res = add (uxly, lxly);
338 uint64_t lx =
static_cast<uint32_t
> (
x);
339 uint64_t uylx = uy*lx;
343 uint64_t ly =
static_cast<uint32_t
> (y);
344 uint64_t lylx = ly*lx;
345 res = add (uylx, lylx);
349 uint64_t lx =
static_cast<uint32_t
> (
x);
350 uint64_t ly =
static_cast<uint32_t
> (y);
373 bool positive = (
x < 0) == (y < 0);
376 uint64_t ux = usx >> 32;
377 uint64_t uy = usy >> 32;
385 uint64_t ly =
static_cast<uint32_t
> (usy);
386 uint64_t uxly = ux*ly;
390 uint64_t lx =
static_cast<uint32_t
> (usx);
391 uint64_t lxly = lx*ly;
399 uint64_t lx =
static_cast<uint32_t
> (usx);
400 uint64_t uylx = uy*lx;
404 uint64_t ly =
static_cast<uint32_t
> (usy);
405 uint64_t lylx = ly*lx;
412 uint64_t lx =
static_cast<uint32_t
> (usx);
413 uint64_t ly =
static_cast<uint32_t
> (usy);
419 if (res >
static_cast<uint64_t
> (max_val ()))
422 return static_cast<int64_t
> (res);
426 if (res >
static_cast<uint64_t
> (min_val ()))
429 return -
static_cast<int64_t
> (res);
433 return positive ? max_val () : min_val ();
468 return (
x + y2) + y2;
497 const double p2_64 =
std::pow (2.0, 64);
500 const uint64_t p2_64my = (~y.
value ()) + 1;
544 uint64_t lx =
static_cast<uint32_t
> (
x);
545 uint64_t ux =
x >> 32;
546 uint64_t ly =
static_cast<uint32_t
> (y);
547 uint64_t uy = y >> 32;
548 uint64_t a = lx * ly;
550 uint64_t uxly = ux*ly;
551 uint64_t uylx = uy*lx;
552 a +=
static_cast<uint32_t
> (uxly); uxly >>= 32;
553 a +=
static_cast<uint32_t
> (uylx); uylx >>= 32;
555 uint64_t uxuy = ux * uy;
556 a += uxly; a += uylx; a += uxuy;
565 sign =
x < 0;
x = fabs (
x);
568 mtis =
static_cast<uint64_t
> (ldexp (
x, 52));
576 double x = ldexp (
static_cast<double> (mtis), exp);
577 return sign ? -
x :
x;
599 for (
short i = 0; i < 4; i++)
621 else if (fabs (y) == 0.5)
632 sign = (sign != (
x.value () < 0));
635 for (
short i = 0; i < 4; i++)
685 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, T1, T2) \
686 template OCTAVE_API bool \
687 octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
689 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
690 INSTANTIATE_INT64_DOUBLE_CMP_OP0 (OP, double, int64_t); \
691 INSTANTIATE_INT64_DOUBLE_CMP_OP0 (OP, double, uint64_t); \
692 INSTANTIATE_INT64_DOUBLE_CMP_OP0 (OP, int64_t, double); \
693 INSTANTIATE_INT64_DOUBLE_CMP_OP0 (OP, uint64_t, double)
704 template <
typename T>
713 if (b == zero || a == one)
739 a_val = a_val * a_val;
746 template <
typename T>
751 template <
typename T>
755 return ((b >= 0 && b < std::numeric_limits<T>::digits
761 template <
typename T>
766 template <
typename T>
770 return ((b >= 0 && b < std::numeric_limits<T>::digits
774 static_cast<double> (b))));
779 template <
typename T>
784 template <
typename T>
788 return ((b >= 0 && b < std::numeric_limits<T>::digits
792 static_cast<double> (b))));
795 #define INSTANTIATE_INTTYPE(T) \
796 template class OCTAVE_API octave_int<T>; \
798 template OCTAVE_API octave_int<T> \
799 pow (const octave_int<T>&, const octave_int<T>&); \
801 template OCTAVE_API octave_int<T> \
802 pow (const double&, const octave_int<T>&); \
804 template OCTAVE_API octave_int<T> \
805 pow (const octave_int<T>&, const double&); \
807 template OCTAVE_API octave_int<T> \
808 pow (const float&, const octave_int<T>&); \
810 template OCTAVE_API octave_int<T> \
811 pow (const octave_int<T>&, const float&); \
813 template OCTAVE_API octave_int<T> \
814 powf (const float&, const octave_int<T>&); \
816 template OCTAVE_API octave_int<T> \
817 powf (const octave_int<T>&, const float&); \
819 template OCTAVE_API octave_int<T> \
820 bitshift (const octave_int<T>&, int, const octave_int<T>&);
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
uint64_t mul_internal(uint64_t x, uint64_t y)
static OCTAVE_API bool emulate_mop(double, int64_t)
static octave_int< T > max(void)
bool bool_value(void) const
static const octave_int zero
double double_value(void) const
float float_value(void) const
static const octave_int one
unsigned int octave_begin_long_double_rounding(void)
void octave_end_long_double_rounding(unsigned int oldcw)
F77_RET_T const F77_DBLE * x
std::complex< double > w(std::complex< double > z, double relerr=0)
double frexp(double x, int *expptr)
octave_int< int64_t > octave_int64
octave_int< uint64_t > octave_uint64
static void umul128(uint64_t x, uint64_t y, uint32_t w[4])
#define INSTANTIATE_INTTYPE(T)
OCTAVE_API octave_uint64 operator-(const octave_uint64 &x, const double &y)
OCTAVE_API octave_uint64 operator+(const octave_uint64 &x, const double &y)
static double dbleget(bool sign, uint32_t mtis, int exp)
OCTAVE_API octave_uint64 operator*(const octave_uint64 &x, const double &y)
#define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP)
static void dblesplit(double x, bool &sign, uint64_t &mtis, int &exp)
octave_int< T > powf(const float &a, const octave_int< T > &b)
OCTAVE_API octave_uint64 operator/(const double &x, const octave_uint64 &y)
#define DEFINE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME)
#define DEFINE_REVERTED_OPERATOR(OP1, OP2)
#define INSTANTIATE_CONVERT_REAL(S)
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
octave_value::octave_value(const Array< char > &chm, char type) return retval