Mercurial > octave
comparison liboctave/oct-inttypes.h @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | fd0a3ac60b0e |
children | 15eefbd9d4e8 |
comparison
equal
deleted
inserted
replaced
11585:1473d0cf86d2 | 11586:12df7854fa7c |
---|---|
49 template<int qsize, bool qsigned> | 49 template<int qsize, bool qsigned> |
50 struct query_integer_type | 50 struct query_integer_type |
51 { | 51 { |
52 public: | 52 public: |
53 static const bool registered = false; | 53 static const bool registered = false; |
54 typedef void type; // Void shall result in a compile-time error if we | 54 typedef void type; // Void shall result in a compile-time error if we |
55 // attempt to use it in computations. | 55 // attempt to use it in computations. |
56 }; | 56 }; |
57 | 57 |
58 #define REGISTER_INT_TYPE(TYPE) \ | 58 #define REGISTER_INT_TYPE(TYPE) \ |
59 template <> \ | 59 template <> \ |
74 REGISTER_INT_TYPE (int64_t); | 74 REGISTER_INT_TYPE (int64_t); |
75 REGISTER_INT_TYPE (uint64_t); | 75 REGISTER_INT_TYPE (uint64_t); |
76 | 76 |
77 // Rationale: Comparators have a single static method, rel(), that returns the | 77 // Rationale: Comparators have a single static method, rel(), that returns the |
78 // result of the binary relation. They also have two static boolean fields: | 78 // result of the binary relation. They also have two static boolean fields: |
79 // ltval, gtval determine the value of x OP y if x < y, x > y, respectively. | 79 // ltval, gtval determine the value of x OP y if x < y, x > y, respectively. |
80 #define REGISTER_OCTAVE_CMP_OP(NM,OP) \ | 80 #define REGISTER_OCTAVE_CMP_OP(NM,OP) \ |
81 class NM \ | 81 class NM \ |
82 { \ | 82 { \ |
83 public: \ | 83 public: \ |
84 static const bool ltval = (0 OP 1), gtval = (1 OP 0); \ | 84 static const bool ltval = (0 OP 1), gtval = (1 OP 0); \ |
107 // size. | 107 // size. |
108 template <class T1, class T2> | 108 template <class T1, class T2> |
109 class prom | 109 class prom |
110 { | 110 { |
111 // Promote to int? | 111 // Promote to int? |
112 static const bool pint = (sizeof (T1) < sizeof (int) | 112 static const bool pint = (sizeof (T1) < sizeof (int) |
113 && sizeof (T2) < sizeof (int)); | 113 && sizeof (T2) < sizeof (int)); |
114 static const bool t1sig = std::numeric_limits<T1>::is_signed; | 114 static const bool t1sig = std::numeric_limits<T1>::is_signed; |
115 static const bool t2sig = std::numeric_limits<T2>::is_signed; | 115 static const bool t2sig = std::numeric_limits<T2>::is_signed; |
116 static const bool psig = | 116 static const bool psig = |
117 (pint || (sizeof (T2) > sizeof (T1) && t2sig) || t1sig); | 117 (pint || (sizeof (T2) > sizeof (T1) && t2sig) || t1sig); |
118 static const int psize = | 118 static const int psize = |
119 (pint ? sizeof (int) : (sizeof (T2) > sizeof (T1) | 119 (pint ? sizeof (int) : (sizeof (T2) > sizeof (T1) |
120 ? sizeof (T2) : sizeof (T1))); | 120 ? sizeof (T2) : sizeof (T1))); |
121 public: | 121 public: |
122 typedef typename query_integer_type<psize, psig>::type type; | 122 typedef typename query_integer_type<psize, psig>::type type; |
123 }; | 123 }; |
124 | 124 |
128 class uiop | 128 class uiop |
129 { | 129 { |
130 typedef typename query_integer_type<size, false>::type utype; | 130 typedef typename query_integer_type<size, false>::type utype; |
131 typedef typename query_integer_type<size, true>::type stype; | 131 typedef typename query_integer_type<size, true>::type stype; |
132 public: | 132 public: |
133 static bool op (utype x, utype y) | 133 static bool op (utype x, utype y) |
134 { return xop::op (x, y); } | 134 { return xop::op (x, y); } |
135 static bool op (stype x, stype y) | 135 static bool op (stype x, stype y) |
136 { return xop::op (x, y); } | 136 { return xop::op (x, y); } |
137 static bool op (stype x, utype y) | 137 static bool op (stype x, utype y) |
138 { return (x < 0) ? xop::ltval : xop::op (static_cast<utype> (x), y); } | 138 { return (x < 0) ? xop::ltval : xop::op (static_cast<utype> (x), y); } |
139 static bool op (utype x, stype y) | 139 static bool op (utype x, stype y) |
140 { return (y < 0) ? xop::gtval : xop::op (x, static_cast<utype> (y)); } | 140 { return (y < 0) ? xop::gtval : xop::op (x, static_cast<utype> (y)); } |
141 }; | 141 }; |
142 | 142 |
143 public: | 143 public: |
144 REGISTER_OCTAVE_CMP_OP (lt, <); | 144 REGISTER_OCTAVE_CMP_OP (lt, <); |
155 static bool | 155 static bool |
156 op (T1 x, T2 y) | 156 op (T1 x, T2 y) |
157 { | 157 { |
158 typedef typename prom<T1, T2>::type PT1; | 158 typedef typename prom<T1, T2>::type PT1; |
159 typedef typename prom<T2, T1>::type PT2; | 159 typedef typename prom<T2, T1>::type PT2; |
160 return uiop<xop, sizeof (PT1)>::op (static_cast<PT1> (x), | 160 return uiop<xop, sizeof (PT1)>::op (static_cast<PT1> (x), |
161 static_cast<PT2> (y)); | 161 static_cast<PT2> (y)); |
162 } | 162 } |
163 | 163 |
164 public: | 164 public: |
165 | 165 |
166 // Mixed comparisons | 166 // Mixed comparisons |
167 template <class xop, class T> | 167 template <class xop, class T> |
168 static bool | 168 static bool |
183 mop (T1 x, T2 y) \ | 183 mop (T1 x, T2 y) \ |
184 { \ | 184 { \ |
185 return xop::op (static_cast<long double> (x), \ | 185 return xop::op (static_cast<long double> (x), \ |
186 static_cast<long double> (y)); \ | 186 static_cast<long double> (y)); \ |
187 } | 187 } |
188 #else | 188 #else |
189 // ... otherwise, use external handlers | 189 // ... otherwise, use external handlers |
190 | 190 |
191 // FIXME: We could declare directly the mop methods as external, | 191 // FIXME: We could declare directly the mop methods as external, |
192 // but we can't do this because bugs in gcc (<= 4.3) prevent | 192 // but we can't do this because bugs in gcc (<= 4.3) prevent |
193 // explicit instantiations later in that case. | 193 // explicit instantiations later in that case. |
209 | 209 |
210 #undef DEFINE_LONG_DOUBLE_CMP_OP | 210 #undef DEFINE_LONG_DOUBLE_CMP_OP |
211 }; | 211 }; |
212 | 212 |
213 // Base integer class. No data, just conversion methods and exception flags. | 213 // Base integer class. No data, just conversion methods and exception flags. |
214 template <class T> | 214 template <class T> |
215 class octave_int_base | 215 class octave_int_base |
216 { | 216 { |
217 protected: | 217 protected: |
218 | 218 |
219 static T min_val () { return std::numeric_limits<T>:: min (); } | 219 static T min_val () { return std::numeric_limits<T>:: min (); } |
221 | 221 |
222 public: | 222 public: |
223 | 223 |
224 // Convert integer value. | 224 // Convert integer value. |
225 template <class S> | 225 template <class S> |
226 static T | 226 static T |
227 truncate_int (const S& value) | 227 truncate_int (const S& value) |
228 { | 228 { |
229 // An exhaustive test whether the max and/or min check can be omitted. | 229 // An exhaustive test whether the max and/or min check can be omitted. |
230 static const bool t_is_signed = std::numeric_limits<T>::is_signed; | 230 static const bool t_is_signed = std::numeric_limits<T>::is_signed; |
231 static const bool s_is_signed = std::numeric_limits<S>::is_signed; | 231 static const bool s_is_signed = std::numeric_limits<S>::is_signed; |
232 static const int t_size = sizeof (T), s_size = sizeof (S); | 232 static const int t_size = sizeof (T), s_size = sizeof (S); |
233 static const bool omit_chk_min = | 233 static const bool omit_chk_min = |
234 (! s_is_signed || (t_is_signed && t_size >= s_size)); | 234 (! s_is_signed || (t_is_signed && t_size >= s_size)); |
235 static const bool omit_chk_max = | 235 static const bool omit_chk_max = |
236 (t_size > s_size || (t_size == s_size | 236 (t_size > s_size || (t_size == s_size |
237 && (! t_is_signed || s_is_signed))); | 237 && (! t_is_signed || s_is_signed))); |
238 // If the check can be omitted, substitute constant false relation. | 238 // If the check can be omitted, substitute constant false relation. |
239 typedef octave_int_cmp_op::cf cf; | 239 typedef octave_int_cmp_op::cf cf; |
240 typedef octave_int_cmp_op::lt lt; | 240 typedef octave_int_cmp_op::lt lt; |
241 typedef octave_int_cmp_op::gt gt; | 241 typedef octave_int_cmp_op::gt gt; |
256 return static_cast<T> (value); | 256 return static_cast<T> (value); |
257 } | 257 } |
258 | 258 |
259 private: | 259 private: |
260 | 260 |
261 // Computes a real-valued threshold for a max/min check. | 261 // Computes a real-valued threshold for a max/min check. |
262 template <class S> | 262 template <class S> |
263 static S | 263 static S |
264 compute_threshold (S val, T orig_val) | 264 compute_threshold (S val, T orig_val) |
265 { | 265 { |
266 val = xround (val); // Fool optimizations (maybe redundant) | 266 val = xround (val); // Fool optimizations (maybe redundant) |
267 // If val is even, but orig_val is odd, we're one unit off. | 267 // If val is even, but orig_val is odd, we're one unit off. |
268 if (orig_val % 2 && val / 2 == xround (val / 2)) | 268 if (orig_val % 2 && val / 2 == xround (val / 2)) |
269 // FIXME -- is this always correct? | 269 // FIXME -- is this always correct? |
270 val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); | 270 val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); |
271 return val; | 271 return val; |
272 } | 272 } |
273 | 273 |
274 public: | 274 public: |
275 // Convert a real number (check NaN and non-int). | 275 // Convert a real number (check NaN and non-int). |
276 template <class S> | 276 template <class S> |
277 static T | 277 static T |
278 convert_real (const S& value) | 278 convert_real (const S& value) |
279 { | 279 { |
280 // Compute proper thresholds. | 280 // Compute proper thresholds. |
281 static const S thmin = compute_threshold (static_cast<S> (min_val ()), min_val ()); | 281 static const S thmin = compute_threshold (static_cast<S> (min_val ()), min_val ()); |
282 static const S thmax = compute_threshold (static_cast<S> (max_val ()), max_val ()); | 282 static const S thmax = compute_threshold (static_cast<S> (max_val ()), max_val ()); |
335 return static_cast<T> (0); | 335 return static_cast<T> (0); |
336 } | 336 } |
337 | 337 |
338 // the overflow behaviour for unsigned integers is guaranteed by C/C++, | 338 // the overflow behaviour for unsigned integers is guaranteed by C/C++, |
339 // so the following should always work. | 339 // so the following should always work. |
340 static T | 340 static T |
341 add (T x, T y) | 341 add (T x, T y) |
342 { | 342 { |
343 T u = x + y; | 343 T u = x + y; |
344 if (u < x) | 344 if (u < x) |
345 { | 345 { |
346 u = octave_int_base<T>::max_val (); | 346 u = octave_int_base<T>::max_val (); |
347 } | 347 } |
348 return u; | 348 return u; |
349 } | 349 } |
350 | 350 |
351 static T | 351 static T |
352 sub (T x, T y) | 352 sub (T x, T y) |
353 { | 353 { |
354 T u = x - y; | 354 T u = x - y; |
355 if (u > x) | 355 if (u > x) |
356 { | 356 { |
358 } | 358 } |
359 return u; | 359 return u; |
360 } | 360 } |
361 | 361 |
362 // Multiplication is done using promotion to wider integer type. If there is | 362 // Multiplication is done using promotion to wider integer type. If there is |
363 // no suitable promotion type, this operation *MUST* be specialized. | 363 // no suitable promotion type, this operation *MUST* be specialized. |
364 static T | 364 static T |
365 mul (T x, T y) | 365 mul (T x, T y) |
366 { | 366 { |
367 // Promotion type for multiplication (if exists). | 367 // Promotion type for multiplication (if exists). |
368 typedef typename query_integer_type<2*sizeof (T), false>::type mptype; | 368 typedef typename query_integer_type<2*sizeof (T), false>::type mptype; |
369 return truncate_int (static_cast<mptype> (x) | 369 return truncate_int (static_cast<mptype> (x) |
370 * static_cast<mptype> (y)); | 370 * static_cast<mptype> (y)); |
371 } | 371 } |
372 | 372 |
373 // Division with rounding to nearest. Note that / and % are probably | 373 // Division with rounding to nearest. Note that / and % are probably |
374 // computed by a single instruction. | 374 // computed by a single instruction. |
375 static T | 375 static T |
376 div (T x, T y) | 376 div (T x, T y) |
377 { | 377 { |
378 if (y != 0) | 378 if (y != 0) |
379 { | 379 { |
380 T z = x / y, w = x % y; | 380 T z = x / y, w = x % y; |
417 return static_cast<uint64_t> (p); | 417 return static_cast<uint64_t> (p); |
418 } | 418 } |
419 #else | 419 #else |
420 // Special handler for 64-bit integer multiply. | 420 // Special handler for 64-bit integer multiply. |
421 template <> | 421 template <> |
422 OCTAVE_API uint64_t | 422 OCTAVE_API uint64_t |
423 octave_int_arith_base<uint64_t, false>::mul (uint64_t, uint64_t); | 423 octave_int_arith_base<uint64_t, false>::mul (uint64_t, uint64_t); |
424 #endif | 424 #endif |
425 | 425 |
426 // Signed integer arithmetics. | 426 // Signed integer arithmetics. |
427 // Rationale: If HAVE_FAST_INT_OPS is defined, the following conditions | 427 // Rationale: If HAVE_FAST_INT_OPS is defined, the following conditions |
438 // | 438 // |
439 // The above conditions are satisfied by most modern platforms. If | 439 // The above conditions are satisfied by most modern platforms. If |
440 // HAVE_FAST_INT_OPS is defined, bit tricks and wraparound arithmetics are used | 440 // HAVE_FAST_INT_OPS is defined, bit tricks and wraparound arithmetics are used |
441 // to avoid conditional jumps as much as possible, thus being friendly to modern | 441 // to avoid conditional jumps as much as possible, thus being friendly to modern |
442 // pipeline processor architectures. | 442 // pipeline processor architectures. |
443 // Otherwise, we fall back to a bullet-proof code that only uses assumptions | 443 // Otherwise, we fall back to a bullet-proof code that only uses assumptions |
444 // guaranteed by the standard. | 444 // guaranteed by the standard. |
445 | 445 |
446 template <class T> | 446 template <class T> |
447 class octave_int_arith_base<T, true> : octave_int_base<T> | 447 class octave_int_arith_base<T, true> : octave_int_base<T> |
448 { | 448 { |
450 typedef typename query_integer_type<sizeof (T), false>::type UT; | 450 typedef typename query_integer_type<sizeof (T), false>::type UT; |
451 public: | 451 public: |
452 | 452 |
453 // Returns 1 for negative number, 0 otherwise. | 453 // Returns 1 for negative number, 0 otherwise. |
454 static T | 454 static T |
455 signbit (T x) | 455 signbit (T x) |
456 { | 456 { |
457 #ifdef HAVE_FAST_INT_OPS | 457 #ifdef HAVE_FAST_INT_OPS |
458 return static_cast<UT> (x) >> std::numeric_limits<T>::digits; | 458 return static_cast<UT> (x) >> std::numeric_limits<T>::digits; |
459 #else | 459 #else |
460 return (x < 0) ? 1 : 0; | 460 return (x < 0) ? 1 : 0; |
461 #endif | 461 #endif |
462 } | 462 } |
463 | 463 |
464 static T | 464 static T |
465 abs (T x) | 465 abs (T x) |
468 // This is close to how GCC does std::abs, but we can't just use std::abs, | 468 // This is close to how GCC does std::abs, but we can't just use std::abs, |
469 // because its behaviour for INT_MIN is undefined and the compiler could | 469 // because its behaviour for INT_MIN is undefined and the compiler could |
470 // discard the following test. | 470 // discard the following test. |
471 T m = x >> std::numeric_limits<T>::digits; | 471 T m = x >> std::numeric_limits<T>::digits; |
472 T y = (x ^ m) - m; | 472 T y = (x ^ m) - m; |
473 if (y < 0) | 473 if (y < 0) |
474 { | 474 { |
475 y = octave_int_base<T>::max_val (); | 475 y = octave_int_base<T>::max_val (); |
476 } | 476 } |
477 return y; | 477 return y; |
478 #else | 478 #else |
491 return y; | 491 return y; |
492 #endif | 492 #endif |
493 } | 493 } |
494 | 494 |
495 static T | 495 static T |
496 signum (T x) | 496 signum (T x) |
497 { | 497 { |
498 // With modest optimizations, this will compile without a jump. | 498 // With modest optimizations, this will compile without a jump. |
499 return ((x > 0) ? 1 : 0) - signbit (x); | 499 return ((x > 0) ? 1 : 0) - signbit (x); |
500 } | 500 } |
501 | 501 |
502 // FIXME -- we do not have an authority what signed shifts should | 502 // FIXME -- we do not have an authority what signed shifts should |
503 // exactly do, so we define them the easy way. Note that Matlab does | 503 // exactly do, so we define them the easy way. Note that Matlab does |
504 // not define signed shifts. | 504 // not define signed shifts. |
531 y = -x; | 531 y = -x; |
532 return y; | 532 return y; |
533 #endif | 533 #endif |
534 } | 534 } |
535 | 535 |
536 static T | 536 static T |
537 add (T x, T y) | 537 add (T x, T y) |
538 { | 538 { |
539 #ifdef HAVE_FAST_INT_OPS | 539 #ifdef HAVE_FAST_INT_OPS |
540 // The typecasts do nothing, but they are here to prevent an optimizing | 540 // The typecasts do nothing, but they are here to prevent an optimizing |
541 // compiler from interfering. Also, the signed operations on small types | 541 // compiler from interfering. Also, the signed operations on small types |
542 // actually return int. | 542 // actually return int. |
543 T u = static_cast<UT> (x) + static_cast<UT> (y); | 543 T u = static_cast<UT> (x) + static_cast<UT> (y); |
544 T ux = u ^ x, uy = u ^ y; | 544 T ux = u ^ x, uy = u ^ y; |
545 if ((ux & uy) < 0) | 545 if ((ux & uy) < 0) |
546 { | 546 { |
547 u = octave_int_base<T>::max_val () + signbit (~u); | 547 u = octave_int_base<T>::max_val () + signbit (~u); |
548 } | 548 } |
549 return u; | 549 return u; |
550 #else | 550 #else |
572 return u; | 572 return u; |
573 #endif | 573 #endif |
574 } | 574 } |
575 | 575 |
576 // This is very similar to addition. | 576 // This is very similar to addition. |
577 static T | 577 static T |
578 sub (T x, T y) | 578 sub (T x, T y) |
579 { | 579 { |
580 #ifdef HAVE_FAST_INT_OPS | 580 #ifdef HAVE_FAST_INT_OPS |
581 // The typecasts do nothing, but they are here to prevent an optimizing | 581 // The typecasts do nothing, but they are here to prevent an optimizing |
582 // compiler from interfering. Also, the signed operations on small types | 582 // compiler from interfering. Also, the signed operations on small types |
583 // actually return int. | 583 // actually return int. |
584 T u = static_cast<UT> (x) - static_cast<UT> (y); | 584 T u = static_cast<UT> (x) - static_cast<UT> (y); |
585 T ux = u ^ x, uy = u ^ ~y; | 585 T ux = u ^ x, uy = u ^ ~y; |
586 if ((ux & uy) < 0) | 586 if ((ux & uy) < 0) |
587 { | 587 { |
588 u = octave_int_base<T>::max_val () + signbit (~u); | 588 u = octave_int_base<T>::max_val () + signbit (~u); |
589 } | 589 } |
590 return u; | 590 return u; |
591 #else | 591 #else |
613 return u; | 613 return u; |
614 #endif | 614 #endif |
615 } | 615 } |
616 | 616 |
617 // Multiplication is done using promotion to wider integer type. If there is | 617 // Multiplication is done using promotion to wider integer type. If there is |
618 // no suitable promotion type, this operation *MUST* be specialized. | 618 // no suitable promotion type, this operation *MUST* be specialized. |
619 static T | 619 static T |
620 mul (T x, T y) | 620 mul (T x, T y) |
621 { | 621 { |
622 // Promotion type for multiplication (if exists). | 622 // Promotion type for multiplication (if exists). |
623 typedef typename query_integer_type<2*sizeof (T), true>::type mptype; | 623 typedef typename query_integer_type<2*sizeof (T), true>::type mptype; |
624 return truncate_int (static_cast<mptype> (x) | 624 return truncate_int (static_cast<mptype> (x) |
625 * static_cast<mptype> (y)); | 625 * static_cast<mptype> (y)); |
626 } | 626 } |
627 | 627 |
628 // Division. | 628 // Division. |
629 static T | 629 static T |
630 div (T x, T y) | 630 div (T x, T y) |
631 { | 631 { |
632 T z; | 632 T z; |
633 if (y == 0) | 633 if (y == 0) |
634 { | 634 { |
648 } | 648 } |
649 else | 649 else |
650 { | 650 { |
651 z = x / y; | 651 z = x / y; |
652 T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! | 652 T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! |
653 if (w <= y - w) | 653 if (w <= y - w) |
654 z -= 1 - (signbit (x) << 1); | 654 z -= 1 - (signbit (x) << 1); |
655 } | 655 } |
656 } | 656 } |
657 else | 657 else |
658 { | 658 { |
660 // FIXME -- this is a workaround due to MSVC's absence of | 660 // FIXME -- this is a workaround due to MSVC's absence of |
661 // std::abs (int64_t). The call to octave_int_abs can't | 661 // std::abs (int64_t). The call to octave_int_abs can't |
662 // overflow, but std::abs (x) can! | 662 // overflow, but std::abs (x) can! |
663 T w = octave_int_abs (x % y); | 663 T w = octave_int_abs (x % y); |
664 | 664 |
665 if (w >= y - w) | 665 if (w >= y - w) |
666 z += 1 - (signbit (x) << 1); | 666 z += 1 - (signbit (x) << 1); |
667 } | 667 } |
668 return z; | 668 return z; |
669 } | 669 } |
670 | 670 |
711 return static_cast<int64_t> (p); | 711 return static_cast<int64_t> (p); |
712 } | 712 } |
713 #else | 713 #else |
714 // Special handler for 64-bit integer multiply. | 714 // Special handler for 64-bit integer multiply. |
715 template <> | 715 template <> |
716 OCTAVE_API int64_t | 716 OCTAVE_API int64_t |
717 octave_int_arith_base<int64_t, true>::mul (int64_t, int64_t); | 717 octave_int_arith_base<int64_t, true>::mul (int64_t, int64_t); |
718 #endif | 718 #endif |
719 | 719 |
720 // This class simply selects the proper arithmetics. | 720 // This class simply selects the proper arithmetics. |
721 template<class T> | 721 template<class T> |
722 class octave_int_arith | 722 class octave_int_arith |
723 : public octave_int_arith_base<T, std::numeric_limits<T>::is_signed> | 723 : public octave_int_arith_base<T, std::numeric_limits<T>::is_signed> |
724 {}; | 724 {}; |
725 | 725 |
726 template <class T> | 726 template <class T> |
727 class | 727 class |
732 | 732 |
733 octave_int (void) : ival () { } | 733 octave_int (void) : ival () { } |
734 | 734 |
735 octave_int (T i) : ival (i) { } | 735 octave_int (T i) : ival (i) { } |
736 | 736 |
737 octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { } | 737 octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { } |
738 | 738 |
739 octave_int (float d) : ival (octave_int_base<T>::convert_real (d)) { } | 739 octave_int (float d) : ival (octave_int_base<T>::convert_real (d)) { } |
740 | 740 |
741 #ifdef OCTAVE_INT_USE_LONG_DOUBLE | 741 #ifdef OCTAVE_INT_USE_LONG_DOUBLE |
742 octave_int (long double d) : ival (octave_int_base<T>::convert_real (d)) { } | 742 octave_int (long double d) : ival (octave_int_base<T>::convert_real (d)) { } |
743 #endif | 743 #endif |
744 | 744 |
745 octave_int (bool b) : ival (b) { } | 745 octave_int (bool b) : ival (b) { } |
746 | 746 |
747 template <class U> | 747 template <class U> |
829 | 829 |
830 static const char *type_name (); | 830 static const char *type_name (); |
831 | 831 |
832 // The following are provided for convenience. | 832 // The following are provided for convenience. |
833 static const octave_int zero, one; | 833 static const octave_int zero, one; |
834 | 834 |
835 // Unsafe. This function exists to support the MEX interface. | 835 // Unsafe. This function exists to support the MEX interface. |
836 // You should not use it anywhere else. | 836 // You should not use it anywhere else. |
837 void *mex_get_data (void) const { return const_cast<T *> (&ival); } | 837 void *mex_get_data (void) const { return const_cast<T *> (&ival); } |
838 | 838 |
839 private: | 839 private: |
1072 template <class T> | 1072 template <class T> |
1073 octave_int<T> | 1073 octave_int<T> |
1074 xmax (const octave_int<T>& x, const octave_int<T>& y) | 1074 xmax (const octave_int<T>& x, const octave_int<T>& y) |
1075 { | 1075 { |
1076 const T xv = x.value (), yv = y.value (); | 1076 const T xv = x.value (), yv = y.value (); |
1077 return octave_int<T> (xv >= yv ? xv : yv); | 1077 return octave_int<T> (xv >= yv ? xv : yv); |
1078 } | 1078 } |
1079 | 1079 |
1080 template <class T> | 1080 template <class T> |
1081 octave_int<T> | 1081 octave_int<T> |
1082 xmin (const octave_int<T>& x, const octave_int<T>& y) | 1082 xmin (const octave_int<T>& x, const octave_int<T>& y) |
1083 { | 1083 { |
1084 const T xv = x.value (), yv = y.value (); | 1084 const T xv = x.value (), yv = y.value (); |
1085 return octave_int<T> (xv <= yv ? xv : yv); | 1085 return octave_int<T> (xv <= yv ? xv : yv); |
1086 } | 1086 } |
1087 | 1087 |
1088 #endif | 1088 #endif |