Fix operator-() for XNS.

This commit is contained in:
Arthur Britto
2012-10-01 13:22:36 -07:00
parent eb2244de76
commit 61e939285e
2 changed files with 8 additions and 20 deletions

View File

@@ -299,18 +299,11 @@ void STAmount::add(Serializer& s) const
}
}
STAmount::STAmount(SField::ref name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true)
STAmount STAmount::createFromInt64(SField::ref name, int64 value)
{
if (value >= 0)
{
mIsNegative = false;
mValue = static_cast<uint64>(value);
}
else
{
mIsNegative = true;
mValue = static_cast<uint64>(-value);
}
return value >= 0
? STAmount(name, static_cast<uint64>(value), false)
: STAmount(name, static_cast<uint64>(-value), true);
}
void STAmount::setValue(const STAmount &a)
@@ -623,7 +616,7 @@ STAmount operator-(const STAmount& v1, const STAmount& v2)
v1.throwComparable(v2);
if (v2.mIsNative)
return STAmount(v1.fName, v1.getSNValue() - v2.getSNValue());
return STAmount::createFromInt64(v1.getFName(), v1.getSNValue() - v2.getSNValue());
int ov1 = v1.mOffset, ov2 = v2.mOffset;
int64 vv1 = static_cast<int64>(v1.mValue), vv2 = static_cast<int64>(v2.mValue);

View File

@@ -216,11 +216,6 @@ protected:
static const uint64 cNotNative = 0x8000000000000000ull;
static const uint64 cPosNative = 0x4000000000000000ull;
STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; }
STAmount(SField::ref name, uint64 value, bool isNegative)
: SerializedType(name), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative)
{ ; }
STAmount(SField::ref name, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
: SerializedType(name), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
mIsNative(isNat), mIsNegative(isNeg) { ; }
@@ -236,8 +231,8 @@ public:
STAmount(uint64 v = 0, bool isNeg = false) : mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg)
{ if (v == 0) mIsNegative = false; }
STAmount(SField::ref n, uint64 v = 0)
: SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(false)
STAmount(SField::ref n, uint64 v = 0, bool isNeg = false)
: SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg)
{ ; }
STAmount(const uint160& uCurrencyID, const uint160& uIssuerID, uint64 uV = 0, int iOff = 0, bool bNegative = false)
@@ -250,7 +245,7 @@ public:
SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg)
{ canonicalize(); }
STAmount(SField::ref n, int64 v);
static STAmount createFromInt64(SField::ref n, int64 v);
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }