GNU Octave  3.8.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-2013 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, uy = y >> 32;
284  uint64_t res;
285  if (ux)
286  {
287  if (uy)
288  goto overflow;
289  else
290  {
291  uint64_t ly = static_cast<uint32_t> (y), uxly = ux*ly;
292  if (uxly >> 32)
293  goto overflow;
294  uxly <<= 32; // never overflows
295  uint64_t lx = static_cast<uint32_t> (x), lxly = lx*ly;
296  res = add (uxly, lxly);
297  }
298  }
299  else if (uy)
300  {
301  uint64_t lx = static_cast<uint32_t> (x), uylx = uy*lx;
302  if (uylx >> 32)
303  goto overflow;
304  uylx <<= 32; // never overflows
305  uint64_t ly = static_cast<uint32_t> (y), lylx = ly*lx;
306  res = add (uylx, lylx);
307  }
308  else
309  {
310  uint64_t lx = static_cast<uint32_t> (x);
311  uint64_t ly = static_cast<uint32_t> (y);
312  res = lx*ly;
313  }
314 
315  return res;
316 
317 overflow:
318  return max_val ();
319 }
320 
321 template <>
322 int64_t
324 {
325  // The signed case is far worse. The problem is that
326  // even if neither integer fits into signed 32-bit range, the result may
327  // still be OK. Uh oh.
328 
329  // Essentially, what we do is compute sign, multiply absolute values
330  // (as above) and impose the sign.
331  // FIXME: can we do something faster if we HAVE_FAST_INT_OPS?
332 
333  uint64_t usx = octave_int_abs (x), usy = octave_int_abs (y);
334  bool positive = (x < 0) == (y < 0);
335 
336  // Get upper words
337  uint64_t ux = usx >> 32, uy = usy >> 32;
338  uint64_t res;
339  if (ux)
340  {
341  if (uy)
342  goto overflow;
343  else
344  {
345  uint64_t ly = static_cast<uint32_t> (usy), uxly = ux*ly;
346  if (uxly >> 32)
347  goto overflow;
348  uxly <<= 32; // never overflows
349  uint64_t lx = static_cast<uint32_t> (usx), lxly = lx*ly;
350  res = uxly + lxly;
351  if (res < uxly)
352  goto overflow;
353  }
354  }
355  else if (uy)
356  {
357  uint64_t lx = static_cast<uint32_t> (usx), uylx = uy*lx;
358  if (uylx >> 32)
359  goto overflow;
360  uylx <<= 32; // never overflows
361  uint64_t ly = static_cast<uint32_t> (usy), lylx = ly*lx;
362  res = uylx + lylx;
363  if (res < uylx)
364  goto overflow;
365  }
366  else
367  {
368  uint64_t lx = static_cast<uint32_t> (usx);
369  uint64_t ly = static_cast<uint32_t> (usy);
370  res = lx*ly;
371  }
372 
373  if (positive)
374  {
375  if (res > static_cast<uint64_t> (max_val ()))
376  {
377  return max_val ();
378  }
379  else
380  return static_cast<int64_t> (res);
381  }
382  else
383  {
384  if (res > static_cast<uint64_t> (-min_val ()))
385  {
386  return min_val ();
387  }
388  else
389  return -static_cast<int64_t> (res);
390  }
391 
392 
393 overflow:
394  return positive ? max_val () : min_val ();
395 
396 }
397 
398 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \
399  template <> \
400  OCTAVE_API octave_ ## SUFFIX \
401  operator OP (const octave_ ## SUFFIX & x, const double& y)
402 
403 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \
404  template <> \
405  OCTAVE_API octave_ ## SUFFIX \
406  operator OP (const double& x, const octave_ ## SUFFIX & y)
407 
409 {
410  return (y < 0) ? x - octave_uint64 (-y) : x + octave_uint64 (y);
411 }
412 
414 { return y + x; }
415 
416 INT_DOUBLE_BINOP_DECL (+, int64)
417 {
418  if (fabs (y) < static_cast<double> (octave_int64::max ()))
419  return x + octave_int64 (y);
420  else
421  {
422  // If the number is within the int64 range (the most common case,
423  // probably), the above will work as expected. If not, it's more
424  // complicated - as long as y is within _twice_ the signed range, the
425  // result may still be an integer. An instance of such an operation is
426  // 3*2**62 + (1+intmin ('int64')) that should yield int64 (2**62) + 1. So
427  // what we do is to try to convert y/2 and add it twice. Note that if y/2
428  // overflows, the result must overflow as well, and that y/2 cannot be a
429  // fractional number.
430  octave_int64 y2 (y / 2);
431  return (x + y2) + y2;
432  }
433 }
434 
435 DOUBLE_INT_BINOP_DECL (+, int64)
436 {
437  return y + x;
438 }
439 
441 {
442  return x + (-y);
443 }
444 
446 {
447  if (x <= static_cast<double> (octave_uint64::max ()))
448  return octave_uint64 (x) - y;
449  else
450  {
451  // Again a trick to get the corner cases right. Things like
452  // 3**2**63 - intmax ('uint64') should produce the correct result, i.e.
453  // int64 (2**63) + 1.
454  const double p2_64 = std::pow (2.0, 64);
455  if (y.bool_value ())
456  {
457  const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2**64 - y
458  return octave_uint64 (x - p2_64) + octave_uint64 (p2_64my);
459  }
460  else
461  return octave_uint64 (p2_64);
462  }
463 }
464 
465 INT_DOUBLE_BINOP_DECL (-, int64)
466 {
467  return x + (-y);
468 }
469 
470 DOUBLE_INT_BINOP_DECL (-, int64)
471 {
472  static const bool twosc = (std::numeric_limits<int64_t>::min ()
474  // In case of symmetric integers (not two's complement), this will probably
475  // be eliminated at compile time.
476  if (twosc && y.value () == std::numeric_limits<int64_t>::min ())
477  {
478  return octave_int64 (x + std::pow (2.0, 63));
479  }
480  else
481  return x + (-y);
482 }
483 
484 // NOTE:
485 // Emulated mixed multiplications are tricky due to possible precision loss.
486 // Here, after sorting out common cases for speed, we follow the strategy
487 // of converting the double number into the form sign * 64-bit integer *
488 // 2**exponent, multiply the 64-bit integers to get a 128-bit number, split that
489 // number into 32-bit words and form 4 double-valued summands (none of which
490 // loses precision), then convert these into integers and sum them. Though it is
491 // not immediately obvious, this should work even w.r.t. rounding (none of the
492 // summands lose precision).
493 
494 // Multiplies two unsigned 64-bit ints to get a 128-bit number represented
495 // as four 32-bit words.
496 static void
497 umul128 (uint64_t x, uint64_t y, uint32_t w[4])
498 {
499  uint64_t lx = static_cast<uint32_t> (x), ux = x >> 32;
500  uint64_t ly = static_cast<uint32_t> (y), uy = y >> 32;
501  uint64_t a = lx * ly;
502  w[0] = a; a >>= 32;
503  uint64_t uxly = ux*ly, uylx = uy*lx;
504  a += static_cast<uint32_t> (uxly); uxly >>= 32;
505  a += static_cast<uint32_t> (uylx); uylx >>= 32;
506  w[1] = a; a >>= 32;
507  uint64_t uxuy = ux * uy;
508  a += uxly; a += uylx; a += uxuy;
509  w[2] = a; a >>= 32;
510  w[3] = a;
511 }
512 
513 // Splits a double into bool sign, unsigned 64-bit mantissa and int exponent
514 static void
515 dblesplit (double x, bool& sign, uint64_t& mtis, int& exp)
516 {
517  sign = x < 0; x = fabs (x);
518  x = gnulib::frexp (x, &exp);
519  exp -= 52;
520  mtis = static_cast<uint64_t> (ldexp (x, 52));
521 }
522 
523 // Gets a double number from a
524 // 32-bit unsigned integer mantissa, exponent, and sign.
525 static double
526 dbleget (bool sign, uint32_t mtis, int exp)
527 {
528  double x = ldexp (static_cast<double> (mtis), exp);
529  return sign ? -x : x;
530 }
531 
533 {
534  if (y >= 0 && y < octave_uint64::max () && y == xround (y))
535  {
536  return x * octave_uint64 (static_cast<uint64_t> (y));
537  }
538  else if (y == 0.5)
539  {
540  return x / octave_uint64 (static_cast<uint64_t> (2));
541  }
542  else if (y < 0 || xisnan (y) || xisinf (y))
543  {
544  return octave_uint64 (x.value () * y);
545  }
546  else
547  {
548  bool sign;
549  uint64_t my;
550  int e;
551  dblesplit (y, sign, my, e);
552  uint32_t w[4];
553  umul128 (x.value (), my, w);
555  for (short i = 0; i < 4; i++)
556  {
557  res += octave_uint64 (dbleget (sign, w[i], e));
558  e += 32;
559  }
560  return res;
561  }
562 }
563 
565 { return y * x; }
566 
567 INT_DOUBLE_BINOP_DECL (*, int64)
568 {
569  if (fabs (y) < octave_int64::max () && y == xround (y))
570  {
571  return x * octave_int64 (static_cast<int64_t> (y));
572  }
573  else if (fabs (y) == 0.5)
574  {
575  return x / octave_int64 (static_cast<uint64_t> (4*y));
576  }
577  else if (xisnan (y) || xisinf (y))
578  {
579  return octave_int64 (x.value () * y);
580  }
581  else
582  {
583  bool sign;
584  uint64_t my;
585  int e;
586  dblesplit (y, sign, my, e);
587  uint32_t w[4];
588  sign = (sign != (x.value () < 0));
589  umul128 (octave_int_abs (x.value ()), my, w);
591  for (short i = 0; i < 4; i++)
592  {
593  res += octave_int64 (dbleget (sign, w[i], e));
594  e += 32;
595  }
596  return res;
597  }
598 }
599 
600 DOUBLE_INT_BINOP_DECL (*, int64)
601 { return y * x; }
602 
604 {
605  return octave_uint64 (x / static_cast<double> (y));
606 }
607 
608 DOUBLE_INT_BINOP_DECL (/, int64)
609 {
610  return octave_int64 (x / static_cast<double> (y));
611 }
612 
614 {
615  if (y >= 0 && y < octave_uint64::max () && y == xround (y))
616  {
617  return x / octave_uint64 (y);
618  }
619  else
620  return x * (1.0/y);
621 }
622 
623 INT_DOUBLE_BINOP_DECL (/, int64)
624 {
625  if (fabs (y) < octave_int64::max () && y == xround (y))
626  {
627  return x / octave_int64 (y);
628  }
629  else
630  return x * (1.0/y);
631 }
632 
633 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \
634  template OCTAVE_API bool \
635  octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
636 
637 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
638  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \
639  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \
640  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \
641  INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double)
642 
649 
650 #endif
651 
652 //template <class T>
653 //bool
654 //xisnan (const octave_int<T>&)
655 //{
656 // return false;
657 //}
658 
659 template <class T>
661 pow (const octave_int<T>& a, const octave_int<T>& b)
662 {
663  octave_int<T> retval;
664 
665  octave_int<T> zero = static_cast<T> (0);
666  octave_int<T> one = static_cast<T> (1);
667 
668  if (b == zero || a == one)
669  retval = one;
670  else if (b < zero)
671  {
672  if (a == -one)
673  retval = (b.value () % 2) ? a : one;
674  else
675  retval = zero;
676  }
677  else
678  {
679  octave_int<T> a_val = a;
680  T b_val = b; // no need to do saturation on b
681 
682  retval = a;
683 
684  b_val -= 1;
685 
686  while (b_val != 0)
687  {
688  if (b_val & 1)
689  retval = retval * a_val;
690 
691  b_val = b_val >> 1;
692 
693  if (b_val)
694  a_val = a_val * a_val;
695  }
696  }
697 
698  return retval;
699 }
700 
701 template <class T>
703 pow (const double& a, const octave_int<T>& b)
704 { return octave_int<T> (pow (a, b.double_value ())); }
705 
706 template <class T>
708 pow (const octave_int<T>& a, const double& b)
709 {
710  return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
711  ? pow (a, octave_int<T> (static_cast<T> (b)))
712  : octave_int<T> (pow (a.double_value (), b)));
713 }
714 
715 template <class T>
717 pow (const float& a, const octave_int<T>& b)
718 { return octave_int<T> (pow (a, b.float_value ())); }
719 
720 template <class T>
722 pow (const octave_int<T>& a, const float& 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 (), static_cast<double> (b))));
727 }
728 
729 // FIXME: Do we really need a differently named single-precision
730 // function integer power function here instead of an overloaded
731 // one?
732 template <class T>
734 powf (const float& a, const octave_int<T>& b)
735 { return octave_int<T> (pow (a, b.float_value ())); }
736 
737 template <class T>
739 powf (const octave_int<T>& a, const float& b)
740 {
741  return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
742  ? pow (a, octave_int<T> (static_cast<T> (b)))
743  : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
744 }
745 
746 #define INSTANTIATE_INTTYPE(T) \
747  template class OCTAVE_API octave_int<T>; \
748  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \
749  template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \
750  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \
751  template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \
752  template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \
753  template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \
754  template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \
755  template OCTAVE_API octave_int<T> \
756  bitshift (const octave_int<T>&, int, const octave_int<T>&); \
757 
762 
767 
768 
769 /*
770 
771 %!assert (intmax ("int64") / intmin ("int64"), int64 (-1))
772 %!assert (intmin ("int64") / int64 (-1), intmax ("int64"))
773 %!assert (int64 (2**63), intmax ("int64"))
774 %!assert (uint64 (2**64), intmax ("uint64"))
775 %!test
776 %! a = 1.9*2^61; b = uint64 (a); b++; assert (b > a);
777 %!test
778 %! a = -1.9*2^61; b = int64 (a); b++; assert (b > a);
779 %!test
780 %! a = int64 (-2**60) + 2; assert (1.25*a == (5*a)/4);
781 %!test
782 %! a = uint64 (2**61) + 2; assert (1.25*a == (5*a)/4);
783 %!assert (int32 (2**31+0.5), intmax ("int32"))
784 %!assert (int32 (-2**31-0.5), intmin ("int32"))
785 %!assert ((int64 (2**62)+1)**1, int64 (2**62)+1)
786 %!assert ((int64 (2**30)+1)**2, int64 (2**60+2**31) + 1)
787 
788 */