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 std::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 (4.2,
"use 'octave::math::round' instead")
67 OCTAVE_DEPRECATED (4.2,
"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;
154 (
pint ?
sizeof (int) : (
sizeof (T2) >
sizeof (T1)
155 ?
sizeof (T2) :
sizeof (T1)));
162 template <
typename xop,
int size>
169 {
return xop::op (
x,
y); }
171 {
return xop::op (
x,
y); }
173 {
return (
x < 0) ? xop::ltval : xop::op (static_cast<utype> (
x),
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)));
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);
510 template <
typename T>
521 return (
x < 0) ? 1 : 0;
536 : ((
x < 0) ? -
x :
x));
543 return ((
x > 0) ? 1 : 0) - __signbit (
x);
605 * static_cast<mptype> (
y));
635 z -= 1 - (__signbit (
x) << 1);
647 z += 1 - (__signbit (
x) << 1);
656 return y != 0 ?
x %
y : 0;
666 return ((r < 0) != (
y < 0)) ? r +
y : r;
673 #if defined (OCTAVE_INT_USE_LONG_DOUBLE) 677 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED) 679 extern OCTAVE_API int64_t
680 octave_external_int64_int64_mul (int64_t, int64_t);
690 long double p =
static_cast<long double> (
x) * static_cast<long double> (
y);
697 retval =
static_cast<int64_t
> (
p);
706 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED) 707 return octave_external_int64_int64_mul (
x,
y);
709 return mul_internal (
x,
y);
723 template <
typename T>
728 template <
typename T>
739 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES) 750 #if defined (OCTAVE_INT_USE_LONG_DOUBLE) 756 template <
typename U>
759 template <
typename U>
771 T
value (
void)
const {
return ival; }
773 const unsigned char *
iptr (
void)
const 774 {
return reinterpret_cast<const unsigned char *
> (& ival); }
786 operator T (
void)
const {
return value (); }
793 #define OCTAVE_INT_UN_OP(OPNAME,NAME) \ 794 inline octave_int<T> \ 797 return octave_int_arith<T>::NAME (ival); \ 804 #undef OCTAVE_INT_UN_OP 807 #define OCTAVE_INT_BIN_OP(OP, NAME, ARGT) \ 808 inline octave_int<T> \ 809 operator OP (const ARGT& y) const \ 811 return octave_int_arith<T>::NAME (ival, y); \ 813 inline octave_int<T>& \ 814 operator OP##= (const ARGT& y) \ 816 ival = octave_int_arith<T>::NAME (ival, y); \ 828 #undef OCTAVE_INT_BIN_OP 833 static int nbits (
void) {
return std::numeric_limits<T>::digits; }
837 static const char * type_name ();
851 template <
typename T>
858 template <
typename T>
871 template <
typename T>
880 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) 882 template <
typename T>
883 OCTAVE_DEPRECATED (4.2,
"use 'octave::math::isnan' instead")
894 template <
typename T>
898 template <
typename T>
902 template <
typename T>
906 template <
typename T>
910 template <
typename T>
917 template <
typename T>
921 template <
typename T>
927 #define OCTAVE_INT_CMP_OP(OP, NAME) \ 928 template <typename T1, typename T2> \ 930 operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \ 932 return octave_int_cmp_op::op<octave_int_cmp_op::NAME, T1, T2> (x.value (), y.value ()); \ 942 #undef OCTAVE_INT_CMP_OP 944 template <
typename T>
946 operator << (std::ostream& os, const octave_int<T>& ival)
952 template <
typename T>
970 operator << (std::ostream& os, const octave_int<int8_t>& ival)
972 os << static_cast<int> (ival.value ());
978 operator << (std::ostream& os, const octave_int<uint8_t>& ival)
980 os << static_cast<unsigned int> (ival.value ());
990 ival =
static_cast<int8_t
> (
tmp);
998 unsigned int tmp = 0;
1000 ival =
static_cast<uint8_t
> (
tmp);
1006 #define OCTAVE_INT_BITCMP_OP(OP) \ 1007 template <typename T> \ 1009 operator OP (const octave_int<T>& x, const octave_int<T>& y) \ 1011 return x.value () OP y.value (); \ 1018 #undef OCTAVE_INT_BITCMP_OP 1021 template <
typename T>
1027 return (
a << n) & mask;
1029 return (
a >> -n) & mask;
1034 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED) 1036 #define DECLARE_EXTERNAL_LONG_DOUBLE_OP(T, OP) \ 1037 extern OCTAVE_API T \ 1038 external_double_ ## T ## _ ## OP (double x, T y); \ 1039 extern OCTAVE_API T \ 1040 external_ ## T ## _double_ ## OP (T x, double y) 1042 #define DECLARE_EXTERNAL_LONG_DOUBLE_OPS(T) \ 1043 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, add); \ 1044 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, sub); \ 1045 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, mul); \ 1046 DECLARE_EXTERNAL_LONG_DOUBLE_OP (T, div) 1053 #define OCTAVE_INT_DOUBLE_BIN_OP0(OP) \ 1054 template <typename T> \ 1055 inline octave_int<T> \ 1056 operator OP (const octave_int<T>& x, const double& y) \ 1058 return octave_int<T> (static_cast<double> (x) OP y); \ 1060 template <typename T> \ 1061 inline octave_int<T> \ 1062 operator OP (const double& x, const octave_int<T>& y) \ 1064 return octave_int<T> (x OP static_cast<double> (y)); \ 1067 #if defined (OCTAVE_INT_USE_LONG_DOUBLE) 1069 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED) 1070 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \ 1071 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \ 1073 inline octave_int64 \ 1074 operator OP (const double& x, const octave_int64& y) \ 1076 return external_double_octave_int64_ ## NAME (x, y); \ 1079 inline octave_uint64 \ 1080 operator OP (const double& x, const octave_uint64& y) \ 1082 return external_double_octave_uint64_ ## NAME (x, y); \ 1085 inline octave_int64 \ 1086 operator OP (const octave_int64& x, const double& y) \ 1088 return external_octave_int64_double_ ## NAME (x, y); \ 1091 inline octave_uint64 \ 1092 operator OP (const octave_uint64& x, const double& y) \ 1094 return external_octave_uint64_double_ ## NAME (x, y); \ 1097 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \ 1098 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \ 1100 inline octave_int64 \ 1101 operator OP (const double& x, const octave_int64& y) \ 1103 return octave_int64 (x OP static_cast<long double> (y.value ())); \ 1106 inline octave_uint64 \ 1107 operator OP (const double& x, const octave_uint64& y) \ 1109 return octave_uint64 (x OP static_cast<long double> (y.value ())); \ 1112 inline octave_int64 \ 1113 operator OP (const octave_int64& x, const double& y) \ 1115 return octave_int64 (static_cast<long double> (x.value ()) OP y); \ 1118 inline octave_uint64 \ 1119 operator OP (const octave_uint64& x, const double& y) \ 1121 return octave_uint64 (static_cast<long double> (x.value ()) OP y); \ 1126 #define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \ 1127 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \ 1129 OCTAVE_API octave_int64 \ 1130 operator OP (const double&, const octave_int64&); \ 1132 OCTAVE_API octave_uint64 \ 1133 operator OP (const double&, const octave_uint64&); \ 1135 OCTAVE_API octave_int64 \ 1136 operator OP (const octave_int64&, const double&); \ 1138 OCTAVE_API octave_uint64 \ 1139 operator OP (const octave_uint64&, const double&); 1148 #undef OCTAVE_INT_DOUBLE_BIN_OP0 1149 #undef OCTAVE_INT_DOUBLE_BIN_OP 1150 #undef DECLARE_EXTERNAL_LONG_DOUBLE_OP 1151 #undef DECLARE_EXTERNAL_LONG_DOUBLE_OPS 1153 #define OCTAVE_INT_DOUBLE_CMP_OP(OP,NAME) \ 1154 template <typename T> \ 1156 operator OP (const octave_int<T>& x, const double& y) \ 1158 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x.value (), y); \ 1160 template <typename T> \ 1162 operator OP (const double& x, const octave_int<T>& y) \ 1164 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x, y.value ()); \ 1174 #undef OCTAVE_INT_DOUBLE_CMP_OP 1178 #define OCTAVE_INT_FLOAT_BIN_OP(OP) \ 1179 template <typename T> \ 1180 inline octave_int<T> \ 1181 operator OP (const octave_int<T>& x, float y) \ 1183 return x OP static_cast<double> (y); \ 1185 template <typename T> \ 1186 inline octave_int<T> \ 1187 operator OP (float x, const octave_int<T>& y) \ 1189 return static_cast<double> (x) OP y; \ 1197 #undef OCTAVE_INT_FLOAT_BIN_OP 1199 #define OCTAVE_INT_FLOAT_CMP_OP(OP) \ 1200 template <typename T> \ 1202 operator OP (const octave_int<T>& x, const float& y) \ 1204 return x OP static_cast<double> (y); \ 1206 template <typename T> \ 1208 operator OP (const float& x, const octave_int<T>& y) \ 1210 return static_cast<double> (x) OP y; \ 1220 #undef OCTAVE_INT_FLOAT_CMP_OP 1222 template <
typename T>
1226 const T xv =
x.value ();
1227 const T yv =
y.value ();
1231 template <
typename T>
1235 const T xv =
x.value ();
1236 const T yv =
y.value ();
octave_int< uint32_t > octave_uint32
static const bool registered
#define OCTAVE_INT_CMP_OP(OP, NAME)
#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(const octave_int< U > &i)
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)
float float_value(void) const
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
query_integer_type< sizeof(T), false >::type UT
const unsigned char * iptr(void) const
query_integer_type< psize, psig >::type type
#define REGISTER_OCTAVE_CMP_OP(NM, OP)
static T truncate_int(const S &value)
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 const F77_DBLE F77_DBLE * d
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
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)
std::complex< double > w(std::complex< double > z, double relerr=0)
#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 octave_int< T > max(void)
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
#define DEFINE_LONG_DOUBLE_CMP_OP(T)
char char_value(void) const
octave_int< T > xmin(const octave_int< T > &x, const octave_int< T > &y)
bool bool_value(void) const
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)
void * mex_get_data(void) const
static octave_int< T > min(void)
static bool op(stype x, utype y)
static const octave_int zero
double double_value(void) const
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)
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
octave_int(const octave_int< T > &i)
static bool mop(double x, T y)
nd group nd example For each display the value
uint64_t mul_internal(uint64_t x, uint64_t y)
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)