24 #if ! defined (octave_oct_inttypes_h)
25 #define octave_oct_inttypes_h 1
27 #include "octave-config.h"
50 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
56 inline long double round (
long double x) {
return roundl (x); }
58 inline long double isnan (
long double x) {
return isnan (static_cast<double> (x)); }
62 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
64 OCTAVE_DEPRECATED (
"use 'octave::math::round' instead")
67 OCTAVE_DEPRECATED (
"use 'octave::math::isnan' instead")
81 template <
int qsize,
bool q
signed>
90 #define REGISTER_INT_TYPE(TYPE) \
92 class query_integer_type<sizeof (TYPE), std::numeric_limits<TYPE>::is_signed> \
95 static const bool registered = true; \
112 #define REGISTER_OCTAVE_CMP_OP(NM,OP) \
116 static const bool ltval = (0 OP 1); \
117 static const bool gtval = (1 OP 0); \
118 template <typename T> \
119 static bool op (T x, T y) { return x OP y; } \
124 #define REGISTER_OCTAVE_CONST_OP(NM,value) \
128 static const bool ltval = value; \
129 static const bool gtval = value; \
130 template <typename T> \
131 static bool op (T, T) { return value; } \
143 template <
typename T1,
typename T2>
147 static const bool pint = (
sizeof (T1) <
sizeof (
int)
148 &&
sizeof (T2) <
sizeof (
int));
149 static const bool t1sig = std::numeric_limits<T1>::is_signed;
150 static const bool t2sig = std::numeric_limits<T2>::is_signed;
152 (pint || (
sizeof (T2) >
sizeof (T1) &&
t2sig) || t1sig);
154 (pint ?
sizeof (
int) : (
sizeof (T2) >
sizeof (T1)
155 ?
sizeof (T2) :
sizeof (T1)));
162 template <
typename xop,
int size>
168 static bool op (utype
x, utype
y)
169 {
return xop::op (x, y); }
170 static bool op (stype
x, stype
y)
171 {
return xop::op (x, y); }
172 static bool op (stype
x, utype
y)
173 {
return (x < 0) ? xop::ltval : xop::op (static_cast<utype> (x), y); }
174 static bool op (utype
x, stype
y)
175 {
return (y < 0) ? xop::gtval : xop::op (x, static_cast<utype> (y)); }
189 template <
typename xop,
typename T1,
typename T2>
196 static_cast<PT2> (y));
202 template <
typename xop,
typename T>
205 {
return xop::op (static_cast<double> (x), y); }
207 template <
typename xop,
typename T>
210 {
return xop::op (x, static_cast<double> (y)); }
212 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
213 # define DECLARE_EXTERNAL_LONG_DOUBLE_CMP_OPS(T) \
214 template <typename xop> static OCTAVE_API bool \
215 external_mop (double, T); \
216 template <typename xop> static OCTAVE_API bool \
217 external_mop (T, double)
219 DECLARE_EXTERNAL_LONG_DOUBLE_CMP_OPS (int64_t);
220 DECLARE_EXTERNAL_LONG_DOUBLE_CMP_OPS (uint64_t);
226 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
227 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
228 # define DEFINE_LONG_DOUBLE_CMP_OP(T) \
229 template <typename xop> \
231 mop (double x, T y) \
233 return external_mop<xop> (x, y); \
235 template <typename xop> \
237 mop (T x, double y) \
239 return external_mop<xop> (x, y); \
242 # define DEFINE_LONG_DOUBLE_CMP_OP(T) \
243 template <typename xop> \
245 mop (double x, T y) \
247 return xop::op (static_cast<long double> (x), \
248 static_cast<long double> (y)); \
250 template <typename xop> \
252 mop (T x, double y) \
254 return xop::op (static_cast<long double> (x), \
255 static_cast<long double> (y)); \
264 # define DEFINE_LONG_DOUBLE_CMP_OP(T) \
265 template <typename xop> static OCTAVE_API bool \
266 emulate_mop (double, T); \
267 template <typename xop> \
269 mop (double x, T y) \
271 return emulate_mop<xop> (x, y); \
273 template <typename xop> static OCTAVE_API bool \
274 emulate_mop (T, double); \
275 template <typename xop> \
277 mop (T x, double y) \
279 return emulate_mop<xop> (x, y); \
286 #undef DEFINE_LONG_DOUBLE_CMP_OP
290 template <
typename T>
299 template <
typename S>
304 static const bool t_is_signed = std::numeric_limits<T>::is_signed;
305 static const bool s_is_signed = std::numeric_limits<S>::is_signed;
306 static const int t_size =
sizeof (T);
307 static const int s_size =
sizeof (S);
309 static const bool omit_chk_min =
310 (! s_is_signed || (t_is_signed && t_size >= s_size));
311 static const bool omit_chk_max =
312 (t_size > s_size || (t_size == s_size
313 && (! t_is_signed || s_is_signed)));
323 if (chk_min::op (value, static_cast<S> (
min_val ())))
327 else if (chk_max::op (value, static_cast<S> (
max_val ())))
332 return static_cast<T
> (
value);
338 template <
typename S>
346 val *= (
static_cast<S
> (1) - (std::numeric_limits<S>::epsilon () / 2));
353 template <
typename S>
363 template <
typename T,
bool is_
signed>
369 template <
typename T>
378 signum (T
x) {
return x ?
static_cast<T
> (1) : static_cast<T> (0); }
390 return static_cast<T
> (0);
427 * static_cast<mptype> (y));
439 if (w >= y-w) z += 1;
452 return y != 0 ? x % y : 0;
459 return y != 0 ? x % y :
x;
463 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
467 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
469 extern OCTAVE_API uint64_t
470 octave_external_uint64_uint64_mul (uint64_t, uint64_t);
480 long double p =
static_cast<long double> (
x) * static_cast<long double> (y);
485 retval =
static_cast<uint64_t
> (
p);
494 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
495 return octave_external_uint64_uint64_mul (x, y);
497 return mul_internal (x, y);
536 template <
typename T>
547 #if defined (OCTAVE_HAVE_FAST_INT_OPS)
548 return static_cast<UT
> (
x) >> std::numeric_limits<T>::digits;
550 return (x < 0) ? 1 : 0;
557 #if defined (OCTAVE_HAVE_FAST_INT_OPS)
561 T
m = x >> std::numeric_limits<T>::digits;
580 y = (x < 0) ? -x : x;
589 return ((x > 0) ? 1 : 0) - __signbit (x);
606 #if defined (OCTAVE_HAVE_FAST_INT_OPS)
629 #if defined (OCTAVE_HAVE_FAST_INT_OPS)
633 T
u =
static_cast<UT
> (
x) + static_cast<UT> (y);
671 #if defined (OCTAVE_HAVE_FAST_INT_OPS)
675 T
u =
static_cast<UT
> (
x) - static_cast<UT> (y);
719 * static_cast<mptype> (y));
749 z -= 1 - (__signbit (x) << 1);
761 z += 1 - (__signbit (x) << 1);
770 return y != 0 ? x % y : 0;
780 return ((r < 0) != (y < 0)) ? r + y : r;
787 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
791 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
793 extern OCTAVE_API int64_t
794 octave_external_int64_int64_mul (int64_t, int64_t);
804 long double p =
static_cast<long double> (
x) * static_cast<long double> (y);
814 retval =
static_cast<int64_t
> (
p);
823 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
824 return octave_external_int64_int64_mul (x, y);
826 return mul_internal (x, y);
840 template <
typename T>
845 template <
typename T>
856 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
859 : ival (
octave_int_base<T>::truncate_int (static_cast<unsigned char> (c)))
867 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
873 template <
typename U>
876 template <
typename U>
888 T
value (
void)
const {
return ival; }
890 const unsigned char *
iptr (
void)
const
891 {
return reinterpret_cast<const unsigned char *
> (& ival); }
903 operator T (
void)
const {
return value (); }
910 #define OCTAVE_INT_UN_OP(OPNAME,NAME) \
911 inline octave_int<T> \
914 return octave_int_arith<T>::NAME (ival); \
921 #undef OCTAVE_INT_UN_OP
924 #define OCTAVE_INT_BIN_OP(OP, NAME, ARGT) \
925 inline octave_int<T> \
926 operator OP (const ARGT& y) const \
928 return octave_int_arith<T>::NAME (ival, y); \
930 inline octave_int<T>& \
931 operator OP##= (const ARGT& y) \
933 ival = octave_int_arith<T>::NAME (ival, y); \
945 #undef OCTAVE_INT_BIN_OP
950 static int nbits (
void) {
return std::numeric_limits<T>::digits; }
954 static const char *type_name ();
968 template <
typename T>
975 template <
typename T>
988 template <
typename T>
997 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
999 template <
typename T>
1000 OCTAVE_DEPRECATED (
"use 'octave::math::isnan' instead")
1011 template <
typename T>
1015 template <
typename T>
1019 template <
typename T>
1023 template <
typename T>
1027 template <
typename T>
1034 template <
typename T>
1038 template <
typename T>
1044 #define OCTAVE_INT_CMP_OP(OP, NAME) \
1045 template <typename T1, typename T2> \
1047 operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \
1049 return octave_int_cmp_op::op<octave_int_cmp_op::NAME, T1, T2> (x.value (), y.value ()); \
1059 #undef OCTAVE_INT_CMP_OP
1061 template <
typename T>
1062 inline std::ostream&
1063 operator << (std::ostream& os, const octave_int<T>& ival)
1065 os << ival.value ();
1069 template <
typename T>
1070 inline std::istream&
1086 inline std::ostream&
1087 operator << (std::ostream& os, const octave_int<int8_t>& ival)
1089 os << static_cast<int> (ival.value ());
1094 inline std::ostream&
1095 operator << (std::ostream& os, const octave_int<uint8_t>& ival)
1097 os << static_cast<unsigned int> (ival.value ());
1102 inline std::istream&
1107 ival =
static_cast<int8_t
> (
tmp);
1112 inline std::istream&
1115 unsigned int tmp = 0;
1117 ival =
static_cast<uint8_t
> (
tmp);
1123 #define OCTAVE_INT_BITCMP_OP(OP) \
1124 template <typename T> \
1126 operator OP (const octave_int<T>& x, const octave_int<T>& y) \
1128 return x.value () OP y.value (); \
1135 #undef OCTAVE_INT_BITCMP_OP
1138 template <
typename T>
1144 return (a << n) & mask;
1146 return (a >> -n) & mask;
1151 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
1153 #define DECLARE_EXTERNAL_LONG_DOUBLE_OP(T, OP) \
1154 extern OCTAVE_API T \
1155 external_double_ ## T ## _ ## OP (double x, T y); \
1156 extern OCTAVE_API T \
1157 external_ ## T ## _double_ ## OP (T x, double y)
1159 #define DECLARE_EXTERNAL_LONG_DOUBLE_OPS(T) \
1160 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, add); \
1161 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, sub); \
1162 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, mul); \
1163 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, div)
1170 #define OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
1171 template <typename T> \
1172 inline octave_int<T> \
1173 operator OP (const octave_int<T>& x, const double& y) \
1175 return octave_int<T> (static_cast<double> (x) OP y); \
1177 template <typename T> \
1178 inline octave_int<T> \
1179 operator OP (const double& x, const octave_int<T>& y) \
1181 return octave_int<T> (x OP static_cast<double> (y)); \
1184 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
1186 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
1187 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
1188 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
1190 inline octave_int64 \
1191 operator OP (const double& x, const octave_int64& y) \
1193 return external_double_octave_int64_ ## NAME (x, y); \
1196 inline octave_uint64 \
1197 operator OP (const double& x, const octave_uint64& y) \
1199 return external_double_octave_uint64_ ## NAME (x, y); \
1202 inline octave_int64 \
1203 operator OP (const octave_int64& x, const double& y) \
1205 return external_octave_int64_double_ ## NAME (x, y); \
1208 inline octave_uint64 \
1209 operator OP (const octave_uint64& x, const double& y) \
1211 return external_octave_uint64_double_ ## NAME (x, y); \
1214 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
1215 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
1217 inline octave_int64 \
1218 operator OP (const double& x, const octave_int64& y) \
1220 return octave_int64 (x OP static_cast<long double> (y.value ())); \
1223 inline octave_uint64 \
1224 operator OP (const double& x, const octave_uint64& y) \
1226 return octave_uint64 (x OP static_cast<long double> (y.value ())); \
1229 inline octave_int64 \
1230 operator OP (const octave_int64& x, const double& y) \
1232 return octave_int64 (static_cast<long double> (x.value ()) OP y); \
1235 inline octave_uint64 \
1236 operator OP (const octave_uint64& x, const double& y) \
1238 return octave_uint64 (static_cast<long double> (x.value ()) OP y); \
1243 #define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
1244 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
1246 OCTAVE_API octave_int64 \
1247 operator OP (const double&, const octave_int64&); \
1249 OCTAVE_API octave_uint64 \
1250 operator OP (const double&, const octave_uint64&); \
1252 OCTAVE_API octave_int64 \
1253 operator OP (const octave_int64&, const double&); \
1255 OCTAVE_API octave_uint64 \
1256 operator OP (const octave_uint64&, const double&);
1265 #undef OCTAVE_INT_DOUBLE_BIN_OP0
1266 #undef OCTAVE_INT_DOUBLE_BIN_OP
1267 #undef DECLARE_EXTERNAL_LONG_DOUBLE_OP
1268 #undef DECLARE_EXTERNAL_LONG_DOUBLE_OPS
1270 #define OCTAVE_INT_DOUBLE_CMP_OP(OP,NAME) \
1271 template <typename T> \
1273 operator OP (const octave_int<T>& x, const double& y) \
1275 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x.value (), y); \
1277 template <typename T> \
1279 operator OP (const double& x, const octave_int<T>& y) \
1281 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x, y.value ()); \
1291 #undef OCTAVE_INT_DOUBLE_CMP_OP
1295 #define OCTAVE_INT_FLOAT_BIN_OP(OP) \
1296 template <typename T> \
1297 inline octave_int<T> \
1298 operator OP (const octave_int<T>& x, float y) \
1300 return x OP static_cast<double> (y); \
1302 template <typename T> \
1303 inline octave_int<T> \
1304 operator OP (float x, const octave_int<T>& y) \
1306 return static_cast<double> (x) OP y; \
1314 #undef OCTAVE_INT_FLOAT_BIN_OP
1316 #define OCTAVE_INT_FLOAT_CMP_OP(OP) \
1317 template <typename T> \
1319 operator OP (const octave_int<T>& x, const float& y) \
1321 return x OP static_cast<double> (y); \
1323 template <typename T> \
1325 operator OP (const float& x, const octave_int<T>& y) \
1327 return static_cast<double> (x) OP y; \
1337 #undef OCTAVE_INT_FLOAT_CMP_OP
1339 template <
typename T>
1343 const T xv = x.
value ();
1344 const T yv = y.
value ();
1348 template <
typename T>
1352 const T xv = x.
value ();
1353 const T yv = y.
value ();
octave_int< uint32_t > octave_uint32
static const bool registered
#define OCTAVE_INT_CMP_OP(OP, NAME)
Octave interface to the compression and uncompression libraries.
#define OCTAVE_INT_BITCMP_OP(OP)
#define OCTAVE_INT_BIN_OP(OP, NAME, ARGT)
OCTAVE_API octave_int< T > pow(const octave_int< T > &, const octave_int< T > &)
octave_int< T > xmax(const octave_int< T > &x, const octave_int< T > &y)
#define OCTAVE_INT_FLOAT_BIN_OP(OP)
static bool op(utype x, stype y)
query_integer_type< size, true >::type stype
static T mul_internal(T x, T y)
identity matrix If supplied two scalar respectively For allows like xample val
static T lshift(T x, int n)
octave_int< T > mod(const octave_int< T > &x, const octave_int< T > &y)
octave_int< int16_t > octave_int16
std::istream & operator>>(std::istream &is, octave_int< T > &ival)
char char_value(void) const
query_integer_type< sizeof(T), false >::type UT
float float_value(void) const
query_integer_type< psize, psig >::type type
octave_int(const octave_int< U > &i)
#define REGISTER_OCTAVE_CMP_OP(NM, OP)
static T truncate_int(const S &value)
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 const F77_DBLE F77_DBLE * d
double double_value(void) const
const unsigned char * iptr(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
octave_int< int32_t > octave_int32
query_integer_type< size, false >::type utype
octave_int< uint16_t > octave_uint16
void * mex_get_data(void) const
static T rshift(T x, int n)
static S compute_threshold(S val, T orig_val)
static bool op(T1 x, T2 y)
static bool op(stype x, stype y)
nd deftypefn *octave_map m
std::complex< double > w(std::complex< double > z, double relerr=0)
static octave_int< T > min(void)
#define OCTAVE_INT_DOUBLE_CMP_OP(OP, NAME)
octave_int< int64_t > octave_int64
OCTAVE_API octave_int< T > powf(const float &a, const octave_int< T > &b)
static T lshift(T x, int n)
#define OCTAVE_INT_UN_OP(OPNAME, NAME)
#define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME)
octave_int< uint64_t > octave_uint64
octave_int(const octave_int< T > &i)
#define DEFINE_LONG_DOUBLE_CMP_OP(T)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
static octave_int< T > max(void)
static const octave_int zero
octave_int< T > xmin(const octave_int< T > &x, const octave_int< T > &y)
static bool op(utype x, utype y)
static bool mop(T x, double y)
charNDArray max(char d, const charNDArray &m)
#define REGISTER_OCTAVE_CONST_OP(NM, value)
#define REGISTER_INT_TYPE(TYPE)
=val(i)}if ode{val(i)}occurs in table i
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup abs(local error in x(i))<
static bool op(stype x, utype y)
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< T > rem(const octave_int< T > &x, const octave_int< T > &y)
the element is set to zero In other the statement xample y
static T mul_internal(T x, T y)
octave_int< T > bitshift(const octave_int< T > &a, int n, const octave_int< T > &mask=std::numeric_limits< T >::max())
#define OCTAVE_INT_FLOAT_CMP_OP(OP)
bool bool_value(void) const
static int byte_size(void)
octave_value operator!(const octave_value &a)
static T convert_real(const S &value)
octave_int< T > operator+(const octave_int< T > &x, const double &y)
write the output to stdout if nargout is
octave_int< uint8_t > octave_uint8
static T rshift(T x, int n)
octave_int< int8_t > octave_int8
static bool mop(double x, T y)
uint64_t mul_internal(uint64_t x, uint64_t y)
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)