GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-inttypes.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2015 John W. Eaton
4 Copyright (C) 2008-2009 Jaroslav Hajek
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <fpucw.h>
29 
30 #include "lo-error.h"
31 
32 #include "oct-inttypes.h"
33 
34 template<class T>
35 const octave_int<T> octave_int<T>::zero (static_cast<T> (0));
36 
37 template<class T>
38 const octave_int<T> octave_int<T>::one (static_cast<T> (1));
39 
40 // define type names.
41 #define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \
42  template <> \
43  OCTAVE_API const char * \
44  octave_int<TYPE>::type_name () { return TYPENAME; }
45 
47 DECLARE_OCTAVE_INT_TYPENAME (int16_t, "int16")
48 DECLARE_OCTAVE_INT_TYPENAME (int32_t, "int32")
49 DECLARE_OCTAVE_INT_TYPENAME (int64_t, "int64")
50 DECLARE_OCTAVE_INT_TYPENAME (uint8_t, "uint8")
51 DECLARE_OCTAVE_INT_TYPENAME (uint16_t, "uint16")
52 DECLARE_OCTAVE_INT_TYPENAME (uint32_t, "uint32")
53 DECLARE_OCTAVE_INT_TYPENAME (uint64_t, "uint64")
54 
55 #ifdef OCTAVE_INT_USE_LONG_DOUBLE
56 
57 #ifdef OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED
58 
59 #define DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES(T) \
60  template <class xop> \
61  bool \
62  octave_int_cmp_op::external_mop (double x, T y) \
63  { \
64  DECL_LONG_DOUBLE_ROUNDING \
65  \
66  BEGIN_LONG_DOUBLE_ROUNDING (); \
67  \
68  bool retval = xop::op (static_cast<long double> (x), \
69  static_cast<long double> (y)); \
70  \
71  END_LONG_DOUBLE_ROUNDING (); \
72  \
73  return retval; \
74  } \
75  \
76  template <class xop> \
77  bool \
78  octave_int_cmp_op::external_mop (T x, double y) \
79  { \
80  DECL_LONG_DOUBLE_ROUNDING \
81  \
82  BEGIN_LONG_DOUBLE_ROUNDING (); \
83  \
84  bool retval = xop::op (static_cast<long double> (x), \
85  static_cast<long double> (y)); \
86  \
87  END_LONG_DOUBLE_ROUNDING (); \
88  \
89  return retval; \
90  }
91 
92 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t)
93 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (uint64_t)
94 
95 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP(OP, T) \
96  template OCTAVE_API bool \
97  octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (double, T); \
98  template OCTAVE_API bool \
99  octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (T, double)
100 
101 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS(T) \
102  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (lt, T); \
103  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (le, T); \
104  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (gt, T); \
105  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ge, T); \
106  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (eq, T); \
107  INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ne, T)
108 
109 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (int64_t);
110 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (uint64_t);
111 
112 uint64_t
113 octave_external_uint64_uint64_mul (uint64_t x, uint64_t y)
114 {
115  DECL_LONG_DOUBLE_ROUNDING
116 
117  BEGIN_LONG_DOUBLE_ROUNDING ();
118 
120 
121  END_LONG_DOUBLE_ROUNDING ();
122 
123  return retval;
124 }
125 
126 int64_t
127 octave_external_int64_int64_mul (int64_t x, int64_t y)
128 {
129  DECL_LONG_DOUBLE_ROUNDING
130 
131  BEGIN_LONG_DOUBLE_ROUNDING ();
132 
134 
135  END_LONG_DOUBLE_ROUNDING ();
136 
137  return retval;
138 }
139 
140 // Note that if we return long double it is apparently possible for
141 // truncation to happen at the point of storing the result in retval,
142 // which can happen after we end long double rounding. Attempt to avoid
143 // that problem by storing the full precision temporary value in the
144 // integer value before we end the long double rounding mode.
145 // Similarly, the conversion from the 64-bit integer type to long double
146 // must also occur in long double rounding mode.
147 
148 #define OCTAVE_LONG_DOUBLE_OP(T, OP, NAME) \
149  T \
150  external_double_ ## T ## _ ## NAME (double x, T y) \
151  { \
152  DECL_LONG_DOUBLE_ROUNDING \
153  \
154  BEGIN_LONG_DOUBLE_ROUNDING (); \
155  \
156  T retval = T (x OP static_cast<long double> (y.value ())); \
157  \
158  END_LONG_DOUBLE_ROUNDING (); \
159  \
160  return retval; \
161  } \
162  \
163  T \
164  external_ ## T ## _double_ ## NAME (T x, double y) \
165  { \
166  DECL_LONG_DOUBLE_ROUNDING \
167  \
168  BEGIN_LONG_DOUBLE_ROUNDING (); \
169  \
170  T retval = T (static_cast<long double> (x.value ()) OP y); \
171  \
172  END_LONG_DOUBLE_ROUNDING (); \
173  \
174  return retval; \
175  }
176 
177 #define OCTAVE_LONG_DOUBLE_OPS(T) \
178  OCTAVE_LONG_DOUBLE_OP (T, +, add); \
179  OCTAVE_LONG_DOUBLE_OP (T, -, sub); \
180  OCTAVE_LONG_DOUBLE_OP (T, *, mul); \
181  OCTAVE_LONG_DOUBLE_OP (T, /, div)
182 
183 OCTAVE_LONG_DOUBLE_OPS(octave_int64);
184 OCTAVE_LONG_DOUBLE_OPS(octave_uint64);
185 
186 #endif
187 
188 #else
189 
190 // Define comparison operators
191 
192 template <class xop>
193 bool
194 octave_int_cmp_op::emulate_mop (uint64_t x, double y)
195 {
196  static const double xxup = std::numeric_limits<uint64_t>::max ();
197  // This converts to the nearest double. Unless there's an equality, the
198  // result is clear.
199  double xx = x;
200  if (xx != y)
201  return xop::op (xx, y);
202  else
203  {
204  // If equality occured we compare as integers.
205  if (xx == xxup)
206  return xop::gtval;
207  else
208  return xop::op (x, static_cast<uint64_t> (xx));
209  }
210 }
211 
212 template <class xop>
213 bool
215 {
216  static const double xxup = std::numeric_limits<int64_t>::max ();
217  static const double xxlo = std::numeric_limits<int64_t>::min ();
218  // This converts to the nearest double. Unless there's an equality, the
219  // result is clear.
220  double xx = x;
221  if (xx != y)
222  return xop::op (xx, y);
223  else
224  {
225  // If equality occured we compare as integers.
226  if (xx == xxup)
227  return xop::gtval;
228  else if (xx == xxlo)
229  return xop::ltval;
230  else
231  return xop::op (x, static_cast<int64_t> (xx));
232  }
233 
234 }
235 
236 // We define double-int operations by reverting the operator
237 
238 // A trait class reverting the operator
239 template <class xop>
240 class rev_op
241 {
242 public:
243  typedef xop op;
244 };
245 
246 #define DEFINE_REVERTED_OPERATOR(OP1,OP2) \
247  template <> \
248  class rev_op<octave_int_cmp_op::OP1> \
249  { \
250  public: \
251  typedef octave_int_cmp_op::OP2 op; \
252  }
253 
258 
259 template <class xop>
260 bool
261 octave_int_cmp_op::emulate_mop (double x, uint64_t y)
262 {
263  typedef typename rev_op<xop>::op rop;
264  return mop<rop> (y, x);
265 }
266 
267 template <class xop>
268 bool
270 {
271  typedef typename rev_op<xop>::op rop;
272  return mop<rop> (y, x);
273 }
274 
275 
276 // Define handlers for int64 multiplication
277 
278 template <>
279 uint64_t
281 {
282  // Get upper words
283  uint64_t ux = x >> 32;
284  uint64_t uy = y >> 32;
285  uint64_t res;
286  if (ux)
287  {
288  if (uy)
289  goto overflow;
290  else
291  {
292  uint64_t ly = static_cast<uint32_t> (y);
293  uint64_t uxly = ux*ly;
294  if (uxly >> 32)
295  goto overflow;
296  uxly <<= 32; // never overflows
297  uint64_t lx = static_cast<uint32_t> (x);
298  uint64_t lxly = lx*ly;
299  res = add (uxly, lxly);
300  }
301  }
302  else if (uy)
303  {
304  uint64_t lx = static_cast<uint32_t> (x);
305  uint64_t uylx = uy*lx;
306  if (uylx >> 32)
307  goto overflow;
308  uylx <<= 32; // never overflows
309  uint64_t ly = static_cast<uint32_t> (y);
310  uint64_t lylx = ly*lx;
311  res = add (uylx, lylx);
312  }
313  else
314  {
315  uint64_t lx = static_cast<uint32_t> (x);
316  uint64_t ly = static_cast<uint32_t> (y);
317  res = lx*ly;
318  }
319 
320  return res;
321 
322 overflow:
323  return max_val ();
324 }
325 
326 template <>
327 int64_t
329 {
330  // The signed case is far worse. The problem is that
331  // even if neither integer fits into signed 32-bit range, the result may
332  // still be OK. Uh oh.
333 
334  // Essentially, what we do is compute sign, multiply absolute values
335  // (as above) and impose the sign.
336  // FIXME: can we do something faster if we HAVE_FAST_INT_OPS?
337 
338  uint64_t usx = octave_int_abs (x);
339  uint64_t usy = octave_int_abs (y);
340  bool positive = (x < 0) == (y < 0);
341 
342  // Get upper words
343  uint64_t ux = usx >> 32;
344  uint64_t uy = usy >> 32;
345  uint64_t res;
346  if (ux)
347  {
348  if (uy)
349  goto overflow;
350  else
351  {
352  uint64_t ly = static_cast<uint32_t> (usy);
353  uint64_t uxly = ux*ly;
354  if (uxly >> 32)
355  goto overflow;
356  uxly <<= 32; // never overflows
357  uint64_t lx = static_cast<uint32_t> (usx);
358  uint64_t lxly = lx*ly;
359  res = uxly + lxly;
360  if (res < uxly)
361  goto overflow;
362  }
363  }
364  else if (uy)
365  {
366  uint64_t lx = static_cast<uint32_t> (usx);
367  uint64_t uylx = uy*lx;
368  if (uylx >> 32)
369  goto overflow;
370  uylx <<= 32; // never overflows
371  uint64_t ly = static_cast<uint32_t> (usy);
372  uint64_t lylx = ly*lx;
373  res = uylx + lylx;
374  if (res < uylx)
375  goto overflow;
376  }
377  else
378  {
379  uint64_t lx = static_cast<uint32_t> (usx);
380  uint64_t ly = static_cast<uint32_t> (usy);
381  res = lx*ly;
382  }
383 
384  if (positive)
385  {
386  if (res > static_cast<uint64_t> (max_val ()))
387  {
388  return max_val ();
389  }
390  else
391  return static_cast<int64_t> (res);
392  }
393  else
394  {
395  if (res > static_cast<uint64_t> (-min_val ()))
396  {
397  return min_val ();
398  }
399  else
400  return -static_cast<int64_t> (res);
401  }
402 
403 
404 overflow:
405  return positive ? max_val () : min_val ();
406 
407 }
408 
409 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \
410  template <> \
411  OCTAVE_API octave_ ## SUFFIX \
412  operator OP (const octave_ ## SUFFIX & x, const double& y)
413 
414 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \
415  template <> \
416  OCTAVE_API octave_ ## SUFFIX \
417  operator OP (const double& x, const octave_ ## SUFFIX & y)
418 
420 {
421  return (y < 0) ? x - octave_uint64 (-y) : x + octave_uint64 (y);
422 }
423 
425 { return y + x; }
426 
428 {
429  if (fabs (y) < static_cast<double> (octave_int64::max ()))
430  return x + octave_int64 (y);
431  else
432  {
433  // If the number is within the int64 range (the most common case,
434  // probably), the above will work as expected. If not, it's more
435  // complicated - as long as y is within _twice_ the signed range, the
436  // result may still be an integer. An instance of such an operation is
437  // 3*2**62 + (1+intmin ('int64')) that should yield int64 (2**62) + 1. So
438  // what we do is to try to convert y/2 and add it twice. Note that if y/2
439  // overflows, the result must overflow as well, and that y/2 cannot be a
440  // fractional number.
441  octave_int64 y2 (y / 2);
442  return (x + y2) + y2;
443  }
444 }
445 
447 {
448  return y + x;
449 }
450 
452 {
453  return x + (-y);
454 }
455 
457 {
458  if (x <= static_cast<double> (octave_uint64::max ()))
459  return octave_uint64 (x) - y;
460  else
461  {
462  // Again a trick to get the corner cases right. Things like
463  // 3**2**63 - intmax ('uint64') should produce the correct result, i.e.
464  // int64 (2**63) + 1.
465  const double p2_64 = std::pow (2.0, 64);
466  if (y.bool_value ())
467  {
468  const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2**64 - y
469  return octave_uint64 (x - p2_64) + octave_uint64 (p2_64my);
470  }
471  else
472  return octave_uint64 (p2_64);
473  }
474 }
475 
477 {
478  return x + (-y);
479 }
480 
482 {
483  static const bool twosc = (std::numeric_limits<int64_t>::min ()
485  // In case of symmetric integers (not two's complement), this will probably
486  // be eliminated at compile time.
487  if (twosc && y.value () == std::numeric_limits<int64_t>::min ())
488  {
489  return octave_int64 (x + std::pow (2.0, 63));
490  }
491  else
492  return x + (-y);
493 }
494 
495 // NOTE:
496 // Emulated mixed multiplications are tricky due to possible precision loss.
497 // Here, after sorting out common cases for speed, we follow the strategy
498 // of converting the double number into the form sign * 64-bit integer *
499 // 2**exponent, multiply the 64-bit integers to get a 128-bit number, split that
500 // number into 32-bit words and form 4 double-valued summands (none of which
501 // loses precision), then convert these into integers and sum them. Though it is
502 // not immediately obvious, this should work even w.r.t. rounding (none of the
503 // summands lose precision).
504 
505 // Multiplies two unsigned 64-bit ints to get a 128-bit number represented
506 // as four 32-bit words.
507 static void
508 umul128 (uint64_t x, uint64_t y, uint32_t w[4])
509 {
510  uint64_t lx = static_cast<uint32_t> (x);
511  uint64_t ux = x >> 32;
512  uint64_t ly = static_cast<uint32_t> (y);
513  uint64_t uy = y >> 32;
514  uint64_t a = lx * ly;
515  w[0] = a; a >>= 32;
516  uint64_t uxly = ux*ly;
517  uint64_t uylx = uy*lx;
518  a += static_cast<uint32_t> (uxly); uxly >>= 32;
519  a += static_cast<uint32_t> (uylx); uylx >>= 32;
520  w[1] = a; a >>= 32;
521  uint64_t uxuy = ux * uy;
522  a += uxly; a += uylx; a += uxuy;
523  w[2] = a; a >>= 32;
524  w[3] = a;
525 }
526 
527 // Splits a double into bool sign, unsigned 64-bit mantissa and int exponent
528 static void
529 dblesplit (double x, bool& sign, uint64_t& mtis, int& exp)
530 {
531  sign = x < 0; x = fabs (x);
532  x = gnulib::frexp (x, &exp);
533  exp -= 52;
534  mtis = static_cast<uint64_t> (ldexp (x, 52));
535 }
536 
537 // Gets a double number from a
538 // 32-bit unsigned integer mantissa, exponent, and sign.
539 static double
540 dbleget (bool sign, uint32_t mtis, int exp)
541 {
542  double x = ldexp (static_cast<double> (mtis), exp);
543  return sign ? -x : x;
544 }
545 
547 {
548  if (y >= 0 && y < octave_uint64::max () && y == xround (y))
549  {
550  return x * octave_uint64 (static_cast<uint64_t> (y));
551  }
552  else if (y == 0.5)
553  {
554  return x / octave_uint64 (static_cast<uint64_t> (2));
555  }
556  else if (y < 0 || xisnan (y) || xisinf (y))
557  {
558  return octave_uint64 (x.value () * y);
559  }
560  else
561  {
562  bool sign;
563  uint64_t my;
564  int e;
565  dblesplit (y, sign, my, e);
566  uint32_t w[4];
567  umul128 (x.value (), my, w);
569  for (short i = 0; i < 4; i++)
570  {
571  res += octave_uint64 (dbleget (sign, w[i], e));
572  e += 32;
573  }
574  return res;
575  }
576 }
577 
579 { return y * x; }
580 
582 {
583  if (fabs (y) < octave_int64::max () && y == xround (y))
584  {
585  return x * octave_int64 (static_cast<int64_t> (y));
586  }
587  else if (fabs (y) == 0.5)
588  {
589  return x / octave_int64 (static_cast<uint64_t> (4*y));
590  }
591  else if (xisnan (y) || xisinf (y))
592  {
593  return octave_int64 (x.value () * y);
594  }
595  else
596  {
597  bool sign;
598  uint64_t my;
599  int e;
600  dblesplit (y, sign, my, e);
601  uint32_t w[4];
602  sign = (sign != (x.value () < 0));
603  umul128 (octave_int_abs (x.value ()), my, w);
605  for (short i = 0; i < 4; i++)
606  {
607  res += octave_int64 (dbleget (sign, w[i], e));
608  e += 32;
609  }
610  return res;
611  }
612 }
613 
615 { return y * x; }
616 
618 {
619  return octave_uint64 (x / static_cast<double> (y));
620 }
621 
623 {
624  return octave_int64 (x / static_cast<double> (y));
625 }
626 
628 {
629  if (y >= 0 && y < octave_uint64::max () && y == xround (y))
630  {
631  return x / octave_uint64 (y);
632  }
633  else
634  return x * (1.0/y);
635 }
636 
638 {
639  if (fabs (y) < octave_int64::max () && y == xround (y))
640  {
641  return x / octave_int64 (y);
642  }
643  else
644  return x * (1.0/y);
645 }
646 
647 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \
648  template OCTAVE_API bool \
649  octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
650 
651 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
652  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \
653  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \
654  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \
655  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double)
656 
663 
664 #endif
665 
666 //template <class T>
667 //bool
668 //xisnan (const octave_int<T>&)
669 //{
670 // return false;
671 //}
672 
673 template <class T>
675 pow (const octave_int<T>& a, const octave_int<T>& b)
676 {
677  octave_int<T> retval;
678 
679  octave_int<T> zero = static_cast<T> (0);
680  octave_int<T> one = static_cast<T> (1);
681 
682  if (b == zero || a == one)
683  retval = one;
684  else if (b < zero)
685  {
686  if (a == -one)
687  retval = (b.value () % 2) ? a : one;
688  else
689  retval = zero;
690  }
691  else
692  {
693  octave_int<T> a_val = a;
694  T b_val = b; // no need to do saturation on b
695 
696  retval = a;
697 
698  b_val -= 1;
699 
700  while (b_val != 0)
701  {
702  if (b_val & 1)
703  retval = retval * a_val;
704 
705  b_val = b_val >> 1;
706 
707  if (b_val)
708  a_val = a_val * a_val;
709  }
710  }
711 
712  return retval;
713 }
714 
715 template <class T>
717 pow (const double& a, const octave_int<T>& b)
718 { return octave_int<T> (pow (a, b.double_value ())); }
719 
720 template <class T>
722 pow (const octave_int<T>& a, const double& b)
723 {
724  return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
725  ? pow (a, octave_int<T> (static_cast<T> (b)))
726  : octave_int<T> (pow (a.double_value (), b)));
727 }
728 
729 template <class T>
731 pow (const float& a, const octave_int<T>& b)
732 { return octave_int<T> (pow (a, b.float_value ())); }
733 
734 template <class T>
736 pow (const octave_int<T>& a, const float& b)
737 {
738  return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
739  ? pow (a, octave_int<T> (static_cast<T> (b)))
740  : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
741 }
742 
743 // FIXME: Do we really need a differently named single-precision
744 // function integer power function here instead of an overloaded
745 // one?
746 template <class T>
748 powf (const float& a, const octave_int<T>& b)
749 { return octave_int<T> (pow (a, b.float_value ())); }
750 
751 template <class T>
753 powf (const octave_int<T>& a, const float& b)
754 {
755  return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
756  ? pow (a, octave_int<T> (static_cast<T> (b)))
757  : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
758 }
759 
760 #define INSTANTIATE_INTTYPE(T) \
761  template class OCTAVE_API octave_int<T>; \
762  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \
763  template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \
764  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \
765  template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \
766  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \
767  template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \
768  template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \
769  template OCTAVE_API octave_int<T> \
770  bitshift (const octave_int<T>&, int, const octave_int<T>&);
771 
776 
781 
782 
783 /*
784 
785 %!assert (intmax ("int64") / intmin ("int64"), int64 (-1))
786 %!assert (intmin ("int64") / int64 (-1), intmax ("int64"))
787 %!assert (int64 (2**63), intmax ("int64"))
788 %!assert (uint64 (2**64), intmax ("uint64"))
789 %!test
790 %! a = 1.9*2^61; b = uint64 (a); b++; assert (b > a);
791 %!test
792 %! a = -1.9*2^61; b = int64 (a); b++; assert (b > a);
793 %!test
794 %! a = int64 (-2**60) + 2; assert (1.25*a == (5*a)/4);
795 %!test
796 %! a = uint64 (2**61) + 2; assert (1.25*a == (5*a)/4);
797 %!assert (int32 (2**31+0.5), intmax ("int32"))
798 %!assert (int32 (-2**31-0.5), intmin ("int32"))
799 %!assert ((int64 (2**62)+1)**1, int64 (2**62)+1)
800 %!assert ((int64 (2**30)+1)**2, int64 (2**60+2**31) + 1)
801 
802 %!assert (uint8 (char (128)), uint8 (128));
803 %!assert (uint8 (char (255)), uint8 (255));
804 %!assert (int8 (char (128)), int8 (128));
805 %!assert (int8 (char (255)), int8 (255));
806 
807 %!assert (uint16 (char (128)), uint16 (128));
808 %!assert (uint16 (char (255)), uint16 (255));
809 %!assert (int16 (char (128)), int16 (128));
810 %!assert (int16 (char (255)), int16 (255));
811 
812 %!assert (uint32 (char (128)), uint32 (128));
813 %!assert (uint32 (char (255)), uint32 (255));
814 %!assert (int32 (char (128)), int32 (128));
815 %!assert (int32 (char (255)), int32 (255));
816 
817 %!assert (uint64 (char (128)), uint64 (128));
818 %!assert (uint64 (char (255)), uint64 (255));
819 %!assert (int64 (char (128)), int64 (128));
820 %!assert (int64 (char (255)), int64 (255));
821 */
double xround(double x)
Definition: lo-mappers.cc:63
bool xisnan(double x)
Definition: lo-mappers.cc:144
static void umul128(uint64_t x, uint64_t y, uint32_t w[4])
double double_value(void) const
Definition: oct-inttypes.h:881
#define DOUBLE_INT_BINOP_DECL(OP, SUFFIX)
#define INT_DOUBLE_BINOP_DECL(OP, SUFFIX)
static const octave_int one
Definition: oct-inttypes.h:941
T octave_int_abs(T x)
Definition: oct-inttypes.h:46
bool xisinf(double x)
Definition: lo-mappers.cc:160
#define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP)
octave_int< T > powf(const float &a, const octave_int< T > &b)
std::complex< double > w(std::complex< double > z, double relerr=0)
octave_int< int64_t > octave_int64
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
static octave_int< T > max(void)
Definition: oct-inttypes.h:932
static OCTAVE_API bool emulate_mop(double, int64_t)
octave_int< uint64_t > octave_uint64
#define DEFINE_REVERTED_OPERATOR(OP1, OP2)
T value(void) const
Definition: oct-inttypes.h:870
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:233
static const octave_int zero
Definition: oct-inttypes.h:941
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)
uint64_t mul_internal(uint64_t x, uint64_t y)
#define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME)
Definition: oct-inttypes.cc:41
F77_RET_T const double * x
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:210
float float_value(void) const
Definition: oct-inttypes.h:883