diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ACE/ace/CDR_Base.cpp | 45 | ||||
-rw-r--r-- | ACE/ace/CDR_Base.h | 65 | ||||
-rw-r--r-- | ACE/ace/CDR_Base.inl | 18 | ||||
-rw-r--r-- | ACE/ace/CDR_Stream.inl | 3 | ||||
-rw-r--r-- | ACE/tests/CDR_Fixed_Test.cpp | 65 |
6 files changed, 114 insertions, 83 deletions
diff --git a/.gitignore b/.gitignore index 0260e31f83a..a4b0d7f9a13 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ lib*.a lib*.so* lib*.dylib *~ +ipch/ /ACE/ace/config.h /ACE/bin/MakeProjectCreator/config/default.features diff --git a/ACE/ace/CDR_Base.cpp b/ACE/ace/CDR_Base.cpp index 505f4cf79e6..54ad10e5172 100644 --- a/ACE/ace/CDR_Base.cpp +++ b/ACE/ace/CDR_Base.cpp @@ -795,7 +795,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_integer (ACE_CDR::LongLong val) int idx = 15; while (true) { - const LongLong mod = val % 10; + const int mod = static_cast<int> (val % 10); const unsigned int digit = (mod < 0) ? -mod : mod; if (high) f.value_[idx--] |= digit << 4; @@ -849,6 +849,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_floating (LongDouble val) #endif Fixed f; + f.digits_ = 0; bool negative = false; if (val < 0) { @@ -867,7 +868,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_floating (LongDouble val) BigFloat frac_part = std::modf (val, &int_part); // Insert the integer part from least to most significant - int idx = (digits_left + 1) / 2 - 1; + int idx = (static_cast<int> (digits_left) + 1) / 2 - 1; bool high = digits_left % 2; for (size_t i = 0; i < digits_left; ++i, high = !high) { @@ -880,7 +881,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_floating (LongDouble val) } // Insert the fractional part from most to least significant - idx = digits_left / 2; + idx = static_cast<int> (digits_left / 2); high = digits_left % 2 == 0; for (size_t i = digits_left; i < MAX_DIGITS; ++i, high = !high) { @@ -896,7 +897,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_floating (LongDouble val) if (frac_part >= 0.5) ++f; // scale set after here so that ++ applies to the fractional part - f.scale_ = MAX_DIGITS - digits_left; + f.scale_ = static_cast<Octet> (MAX_DIGITS - digits_left); f.normalize (); f.value_[15] |= negative ? NEGATIVE : POSITIVE; return f; @@ -917,8 +918,8 @@ void ACE_CDR::Fixed::normalize (UShort min_scale) && this->scale_ - 2 * (bytes + 1) >= min_scale && !(this->value_[14 - bytes] & 0xf); const size_t nibbles = 1 /*[15].high*/ + bytes * 2 + extra_nibble; - this->digits_ -= nibbles; - this->scale_ -= nibbles; + this->digits_ -= static_cast<Octet> (nibbles); + this->scale_ -= static_cast<Octet> (nibbles); if (extra_nibble) { @@ -958,7 +959,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_string (const char *str) { if (str[iter - 1] == '.') { - f.scale_ = span - iter; + f.scale_ = static_cast<Octet> (span - iter); if (--iter == 0) break; // skip '.' } @@ -990,7 +991,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::from_octets (const Octet *array, int len) return f; } -ACE_CDR::Fixed::operator LongLong () const +ACE_CDR::Fixed::operator ACE_CDR::LongLong () const { LongLong val (0); @@ -1003,12 +1004,12 @@ ACE_CDR::Fixed::operator LongLong () const return val; } -ACE_CDR::Fixed::operator LongDouble () const +ACE_CDR::Fixed::operator ACE_CDR::LongDouble () const { - LongDouble val (0); + LongDouble val = ACE_CDR_LONG_DOUBLE_INITIALIZER; for (int i = this->digits_ - 1; i >= this->scale_; --i) - val = 10 * val + this->digit (i); + ACE_CDR_LONG_DOUBLE_ASSIGNMENT (val, 10 * val + this->digit (i)); for (int i = this->scale_ - 1; i >= 0; --i) val += this->digit (i) * std::pow (10.0l, i - this->scale_); @@ -1034,7 +1035,7 @@ ACE_CDR::Fixed ACE_CDR::Fixed::round (UShort scale) const { f.scale_ = 0; ++f; - f.scale_ = scale; + f.scale_ = static_cast<Octet> (scale); } if (negative && !!f) f.value_[15] = (f.value_[15] & 0xf0) | NEGATIVE; @@ -1150,7 +1151,7 @@ ACE_CDR::Fixed::ConstIterator ACE_CDR::Fixed::pre_add (const ACE_CDR::Fixed &f) if (this->digits_ > MAX_DIGITS) { for (size_t i = 0; i < this->digits_ - MAX_DIGITS; ++i) - this->digit (i, 0); + this->digit (static_cast<int> (i), 0); this->normalize (this->scale_ - MAX_DIGITS - this->digits_); this->digits_ = MAX_DIGITS; } @@ -1292,8 +1293,8 @@ ACE_CDR::Fixed &ACE_CDR::Fixed::operator*= (const Fixed &rhs) for (int col = 0; col < this->digits_ + rhs.digits_; ++col) { - for (int row = std::max (0, col - this->digits_ + 1); - row < std::min (col + 1, int (rhs.digits_)); ++row) + for (int row = (std::max) (0, col - this->digits_ + 1); + row < (std::min) (col + 1, int (rhs.digits_)); ++row) carry += this->digit (col - row) * rhs.digit (row); temp[col] = carry % 10; carry /= 10; @@ -1405,13 +1406,16 @@ std::istream &operator>> (std::istream &lhs, ACE_CDR::Fixed &rhs) { double num; lhs >> num; - rhs = ACE_CDR::Fixed::from_floating (num); + ACE_CDR::LongDouble ld; + ACE_CDR_LONG_DOUBLE_ASSIGNMENT (ld, num); + rhs = ACE_CDR::Fixed::from_floating (ld); return lhs; } #endif -bool operator< (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) +bool ACE_CDR::Fixed::less (const ACE_CDR::Fixed &rhs) const { + const Fixed &lhs = *this; if (lhs.signbit () != rhs.signbit ()) return lhs.signbit (); @@ -1440,8 +1444,8 @@ bool operator< (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) return true; } - const int common_frac = std::min (a.scale_, b.scale_), - common_dig = std::min (a_int_dig, b_int_dig) + common_frac, + const int common_frac = (std::min) (a.scale_, b.scale_), + common_dig = (std::min) (a_int_dig, b_int_dig) + common_frac, a_off = a.scale_ - common_frac, // a's offset (more scale than b) b_off = b.scale_ - common_frac; // b's offset (more scale than a) @@ -1460,8 +1464,9 @@ bool operator< (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) return false; } -bool operator== (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) +bool ACE_CDR::Fixed::equal (const ACE_CDR::Fixed &rhs) const { + const Fixed &lhs = *this; if (lhs.signbit () != rhs.signbit ()) return false; diff --git a/ACE/ace/CDR_Base.h b/ACE/ace/CDR_Base.h index 3afa0615aaa..4b2bfa405aa 100644 --- a/ACE/ace/CDR_Base.h +++ b/ACE/ace/CDR_Base.h @@ -367,8 +367,13 @@ public: class ACE_Export Fixed { public: - static const size_t MAX_DIGITS = 31, - MAX_STRING_SIZE = 3 + MAX_DIGITS; // includes -, ., terminator + enum + { + MAX_DIGITS = 31, + MAX_STRING_SIZE = 3 + MAX_DIGITS, // includes -, ., terminator + POSITIVE = 0xc, + NEGATIVE = 0xd, + }; static Fixed from_integer (LongLong val = 0); static Fixed from_integer (ULongLong val); @@ -406,32 +411,8 @@ public: Octet digit (int n) const; void digit (int n, int value); - friend ACE_Export - ACE_OSTREAM_TYPE &::operator<< (ACE_OSTREAM_TYPE &lhs, - const Fixed &rhs); - -#ifndef ACE_LACKS_IOSTREAM_TOTALLY - friend ACE_Export - std::istream &::operator>> (std::istream &lhs, Fixed &rhs); -#endif - - friend ACE_Export - bool ::operator< (const Fixed &lhs, const Fixed &rhs); - - friend ACE_Export - bool ::operator> (const Fixed &lhs, const Fixed &rhs); - - friend ACE_Export - bool ::operator>= (const Fixed &lhs, const Fixed &rhs); - - friend ACE_Export - bool ::operator<= (const Fixed &lhs, const Fixed &rhs); - - friend ACE_Export - bool ::operator== (const Fixed &lhs, const Fixed &rhs); - - friend ACE_Export - bool ::operator!= (const Fixed &lhs, const Fixed &rhs); + bool less (const Fixed &rhs) const; + bool equal (const Fixed &rhs) const; class Proxy { @@ -518,8 +499,6 @@ public: /// from the type information (for example, IDL). Octet scale_; - static const Octet POSITIVE = 0xc, NEGATIVE = 0xd; - /// remove trailing zeros, shift down and reduce digits and scale void normalize (UShort min_scale = 0); @@ -545,6 +524,32 @@ public: }; ACE_Export +ACE_OSTREAM_TYPE &operator<< (ACE_OSTREAM_TYPE &lhs, const ACE_CDR::Fixed &rhs); + +#ifndef ACE_LACKS_IOSTREAM_TOTALLY +ACE_Export +std::istream &operator>> (std::istream &lhs, ACE_CDR::Fixed &rhs); +#endif + +ACE_Export +bool operator< (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +bool operator> (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +bool operator>= (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +bool operator<= (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +bool operator== (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +bool operator!= (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export ACE_CDR::Fixed operator+ (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); ACE_Export diff --git a/ACE/ace/CDR_Base.inl b/ACE/ace/CDR_Base.inl index ef67ad3a1c9..f2d9de3b492 100644 --- a/ACE/ace/CDR_Base.inl +++ b/ACE/ace/CDR_Base.inl @@ -323,7 +323,7 @@ ACE_CDR::Fixed::Proxy::operator-- () } ACE_INLINE -ACE_CDR::Fixed::Proxy::operator Octet () const +ACE_CDR::Fixed::Proxy::operator ACE_CDR::Octet () const { return this->high_nibble_ ? this->element_ >> 4 : (this->element_ & 0xf); } @@ -369,7 +369,7 @@ ACE_CDR::Fixed::Iterator::operator* () ACE_INLINE ACE_CDR::Fixed::Iterator & ACE_CDR::Fixed::Iterator::operator+= (std::ptrdiff_t n) { - this->digit_ += n; + this->digit_ += static_cast<int> (n); return *this; } @@ -429,7 +429,7 @@ ACE_CDR::Fixed::ConstIterator::operator* () ACE_INLINE ACE_CDR::Fixed::ConstIterator & ACE_CDR::Fixed::ConstIterator::operator+= (std::ptrdiff_t n) { - this->digit_ += n; + this->digit_ += static_cast<int> (n); return *this; } @@ -574,6 +574,12 @@ operator/ (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) } ACE_INLINE bool +operator< (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) +{ + return lhs.less (rhs); +} + +ACE_INLINE bool operator> (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) { return rhs < lhs; @@ -592,6 +598,12 @@ operator<= (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) } ACE_INLINE bool +operator== (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) +{ + return lhs.equal (rhs); +} + +ACE_INLINE bool operator!= (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs) { return !(lhs == rhs); diff --git a/ACE/ace/CDR_Stream.inl b/ACE/ace/CDR_Stream.inl index fdc741146f6..0103d279224 100644 --- a/ACE/ace/CDR_Stream.inl +++ b/ACE/ace/CDR_Stream.inl @@ -726,7 +726,8 @@ ACE_InputCDR::read_fixed (ACE_CDR::Fixed &x) if (!this->read_1 (a + i)) return false; const unsigned low = a[i] & 0xf; - if (low == 0xc || low == 0xd) + if (low == ACE_CDR::Fixed::POSITIVE || + low == ACE_CDR::Fixed::NEGATIVE) { x = ACE_CDR::Fixed::from_octets (a, i + 1); return true; diff --git a/ACE/tests/CDR_Fixed_Test.cpp b/ACE/tests/CDR_Fixed_Test.cpp index fb049b8fc15..c4244370de9 100644 --- a/ACE/tests/CDR_Fixed_Test.cpp +++ b/ACE/tests/CDR_Fixed_Test.cpp @@ -48,14 +48,17 @@ int run_main (int, ACE_TCHAR *[]) ACE_START_TEST (ACE_TEXT ("CDR_Fixed_Test")); typedef ACE_CDR::Fixed Fixed; + typedef ACE_CDR::LongLong LongLong; + typedef ACE_CDR::ULongLong ULongLong; + typedef ACE_CDR::LongDouble LongDouble; - const Fixed f1 = Fixed::from_integer (-1234567890l), - f2 = Fixed::from_integer (987654321ul), + const Fixed f1 = Fixed::from_integer (LongLong (-1234567890l)), + f2 = Fixed::from_integer (ULongLong (987654321ul)), f3 = Fixed::from_string ("612578912487901265.90125789"); - TEST_EQUAL (ACE_CDR::LongLong (-1234567890l), ACE_CDR::LongLong (f1)); - TEST_EQUAL (ACE_CDR::LongLong (987654321), ACE_CDR::LongLong (f2)); - TEST_EQUAL (ACE_CDR::LongLong (612578912487901265ul), ACE_CDR::LongLong (f3)); + TEST_EQUAL (LongLong (-1234567890l), LongLong (f1)); + TEST_EQUAL (LongLong (987654321), LongLong (f2)); + TEST_EQUAL (LongLong (612578912487901265ul), LongLong (f3)); TEST_EQUAL (0, f1.fixed_scale ()); TEST_EQUAL (10, f1.fixed_digits ()); @@ -94,24 +97,28 @@ int run_main (int, ACE_TCHAR *[]) f7 = Fixed::from_string ("-0.005"); EXPECT ("-0.01", f7.round (2)); EXPECT ("0.00", f7.truncate (2)); - - const Fixed f8 = Fixed::from_floating (1234.45l); - TEST_EQUAL (ACE_CDR::LongLong (1234), ACE_CDR::LongLong (f8)); - TEST_EQUAL (ACE_CDR::LongDouble (1234.45l), ACE_CDR::LongDouble (f8)); - EXPECT ("1234.449999999999999955591079015", f8); - - const Fixed f9 = Fixed::from_floating (-0.3125l); + + LongDouble ld1; + ACE_CDR_LONG_DOUBLE_ASSIGNMENT (ld1, 1234.45); + const Fixed f8 = Fixed::from_floating (ld1); + TEST_EQUAL (LongLong (1234), LongLong (f8)); + + LongDouble ld2; + ACE_CDR_LONG_DOUBLE_ASSIGNMENT (ld2, -0.3125); + const Fixed f9 = Fixed::from_floating (ld2); EXPECT ("-0.3125", f9); - const Fixed f10 = Fixed::from_floating (0.125l); + LongDouble ld3; + ACE_CDR_LONG_DOUBLE_ASSIGNMENT (ld3, 0.125); + const Fixed f10 = Fixed::from_floating (ld3); EXPECT ("0.125", f10); - Fixed f11 = Fixed::from_integer (-1l); - TEST_EQUAL (ACE_CDR::LongLong (-1), ACE_CDR::LongLong (f11)); + Fixed f11 = Fixed::from_integer (LongLong (-1l)); + TEST_EQUAL (LongLong (-1), LongLong (f11)); TEST_EQUAL (false, !f11); ++f11; TEST_EQUAL (true, !f11); - TEST_EQUAL (ACE_CDR::LongLong (0), ACE_CDR::LongLong (f11)); + TEST_EQUAL (LongLong (0), LongLong (f11)); TEST_EQUAL (Fixed::from_integer (), f11); f11 += Fixed::from_string ("0.124357891"); ++f11; @@ -120,10 +127,10 @@ int run_main (int, ACE_TCHAR *[]) --f11; TEST_EQUAL (Fixed::from_string ("-0.875642109"), f11); - TEST_EQUAL (true, Fixed::from_integer (-4l) < Fixed::from_integer (2l)); - TEST_EQUAL (true, Fixed::from_integer (-4l) < Fixed::from_integer (-2l)); - TEST_EQUAL (false, Fixed::from_integer (4l) < Fixed::from_integer (-2l)); - TEST_EQUAL (false, Fixed::from_integer (4l) < Fixed::from_integer (2l)); + TEST_EQUAL (true, Fixed::from_integer (LongLong (-4)) < Fixed::from_integer (LongLong (2))); + TEST_EQUAL (true, Fixed::from_integer (LongLong (-4)) < Fixed::from_integer (LongLong (-2))); + TEST_EQUAL (false, Fixed::from_integer (LongLong (4)) < Fixed::from_integer (LongLong (-2))); + TEST_EQUAL (false, Fixed::from_integer (LongLong (4)) < Fixed::from_integer (LongLong (2))); TEST_EQUAL (true, Fixed::from_string ("2.17") < Fixed::from_string ("3.142")); TEST_EQUAL (true, Fixed::from_string ("10.1") < Fixed::from_string ("100")); @@ -137,10 +144,10 @@ int run_main (int, ACE_TCHAR *[]) Fixed f13 = f12--; TEST_EQUAL (--f13, f12); - Fixed f14 = Fixed::from_integer (9l); + Fixed f14 = Fixed::from_integer (LongLong (9)); TEST_EQUAL (1, f14.fixed_digits ()); ++f14; - TEST_EQUAL (Fixed::from_integer (10l), f14); + TEST_EQUAL (Fixed::from_integer (LongLong (10)), f14); TEST_EQUAL (Fixed::from_string ("778.33"), Fixed::from_string ("12.9") + Fixed::from_string ("765.43")); @@ -155,7 +162,7 @@ int run_main (int, ACE_TCHAR *[]) TEST_EQUAL (f15, f14); Fixed f16 = Fixed::from_string ("123.4567890123456789012345678901"); - f16 += Fixed::from_integer (9876l); + f16 += Fixed::from_integer (LongLong (9876)); const Fixed f17 = Fixed::from_string ("9999.456789012345678901234567890"); TEST_EQUAL (f17, f16); @@ -163,22 +170,22 @@ int run_main (int, ACE_TCHAR *[]) f18 -= Fixed::from_string ("123546789"); EXPECT ("74307402", f18); - Fixed f19 = Fixed::from_integer (9l); - f19 -= Fixed::from_integer (10l); + Fixed f19 = Fixed::from_integer (LongLong (9)); + f19 -= Fixed::from_integer (LongLong (10)); EXPECT ("-1", f19); - Fixed f20 = Fixed::from_integer (99l); - f20 += Fixed::from_integer (99l); + Fixed f20 = Fixed::from_integer (LongLong (99)); + f20 += Fixed::from_integer (LongLong (99)); EXPECT ("198", f20); // carry extra digit Fixed f21 = Fixed::from_string ("7.532"); f21 -= Fixed::from_string ("4.91"); EXPECT ("2.622", f21); - Fixed f22 = Fixed::from_integer (-99l) * Fixed::from_integer (-9l); + Fixed f22 = Fixed::from_integer (LongLong (-99)) * Fixed::from_integer (LongLong (-9)); EXPECT ("891", f22); - Fixed f23 = Fixed::from_integer (9l) * Fixed::from_integer (-99l); + Fixed f23 = Fixed::from_integer (LongLong (9)) * Fixed::from_integer (LongLong (-99)); EXPECT ("-891", f23); Fixed f24 = Fixed::from_string ("-3.4") * Fixed::from_string ("5.67"); |