Mercurial > octave-nkf
comparison liboctave/oct-inttypes.h @ 8333:9238637cb81c
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 18 Nov 2008 11:14:31 -0500 |
parents | c374691576f6 |
children | 5abe5ae55465 |
comparison
equal
deleted
inserted
replaced
8332:34fde4755a0f | 8333:9238637cb81c |
---|---|
43 #ifdef min | 43 #ifdef min |
44 #undef min | 44 #undef min |
45 #undef max | 45 #undef max |
46 #endif | 46 #endif |
47 | 47 |
48 // FIXME: we define this by our own because some compilers, such as MSVC, | 48 // FIXME -- we define this by our own because some compilers, such as |
49 // do not provide std::abs (int64_t) and std::abs (uint64_t). In the future, | 49 // MSVC, do not provide std::abs (int64_t) and std::abs (uint64_t). In |
50 // it should go away in favor of std::abs. | 50 // the future, it should go away in favor of std::abs. |
51 template <class T> | 51 template <class T> |
52 inline T octave_int_abs (T x) { return x >= 0 ? x : -x; } | 52 inline T octave_int_abs (T x) { return x >= 0 ? x : -x; } |
53 | 53 |
54 // Query for an integer type of certain sizeof, and signedness. | 54 // Query for an integer type of certain sizeof, and signedness. |
55 template<int qsize, bool qsigned> | 55 template<int qsize, bool qsigned> |
280 compute_threshold (S val, T orig_val) | 280 compute_threshold (S val, T orig_val) |
281 { | 281 { |
282 val = xround (val); // Fool optimizations (maybe redundant) | 282 val = xround (val); // Fool optimizations (maybe redundant) |
283 // If val is even, but orig_val is odd, we're one unit off. | 283 // If val is even, but orig_val is odd, we're one unit off. |
284 if (orig_val % 2 && val / 2 == xround (val / 2)) | 284 if (orig_val % 2 && val / 2 == xround (val / 2)) |
285 // FIXME: is this always correct? | 285 // FIXME -- is this always correct? |
286 val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); | 286 val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); |
287 return val; | 287 return val; |
288 } | 288 } |
289 | 289 |
290 public: | 290 public: |
544 { | 544 { |
545 // With modest optimizations, this will compile without a jump. | 545 // With modest optimizations, this will compile without a jump. |
546 return ((x > 0) ? 1 : 0) - signbit (x); | 546 return ((x > 0) ? 1 : 0) - signbit (x); |
547 } | 547 } |
548 | 548 |
549 // FIXME: We do not have an authority what signed shifts should exactly do, so | 549 // FIXME -- we do not have an authority what signed shifts should |
550 // we define them the easy way. Note that Matlab does not define signed | 550 // exactly do, so we define them the easy way. Note that Matlab does |
551 // shifts. | 551 // not define signed shifts. |
552 | 552 |
553 static T | 553 static T |
554 rshift (T x, int n) { return x >> n; } | 554 rshift (T x, int n) { return x >> n; } |
555 | 555 |
556 static T | 556 static T |
712 } | 712 } |
713 } | 713 } |
714 else | 714 else |
715 { | 715 { |
716 z = x / y; | 716 z = x / y; |
717 // FIXME: this is a workaround due to MSVC's absence of std::abs (int64_t). | 717 // FIXME -- this is a workaround due to MSVC's absence of |
718 T w = octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! | 718 // std::abs (int64_t). The call to octave_int_abs can't |
719 // overflow, but std::abs (x) can! | |
720 T w = octave_int_abs (x % y); | |
721 | |
719 if (w >= y - w) | 722 if (w >= y - w) |
720 z += 1 - (signbit (x) << 1); | 723 z += 1 - (signbit (x) << 1); |
721 } | 724 } |
722 return z; | 725 return z; |
723 } | 726 } |
882 template <class T> | 885 template <class T> |
883 inline bool | 886 inline bool |
884 xisnan (const octave_int<T>&) | 887 xisnan (const octave_int<T>&) |
885 { return false; } | 888 { return false; } |
886 | 889 |
887 // FIXME: Can/should any of these be inline? | 890 // FIXME -- can/should any of these be inline? |
888 | 891 |
889 template <class T> | 892 template <class T> |
890 extern OCTAVE_API octave_int<T> | 893 extern OCTAVE_API octave_int<T> |
891 pow (const octave_int<T>&, const octave_int<T>&); | 894 pow (const octave_int<T>&, const octave_int<T>&); |
892 | 895 |