A simplification.

This commit is contained in:
JoelKatz
2012-04-13 16:29:42 -07:00
parent f5464e02b6
commit a3c0661451
2 changed files with 6 additions and 12 deletions

View File

@@ -15,7 +15,7 @@ void STAmount::canonicalize()
{
if (value == 0)
{
offset = 0;
offset = -100;
value = 0;
return;
}
@@ -34,7 +34,8 @@ void STAmount::canonicalize()
++offset;
}
assert( (value == 0) || ( (value >= cMinValue) && (value <= cMaxValue) ) );
assert( (offset >= cMinOffset) && (offset <= cMaxOffset) );
assert( (value == 0) || (offset >= cMinOffset) && (offset <= cMaxOffset) );
assert( (value != 0) || (offset != -100) );
}
STAmount* STAmount::construct(SerializerIterator& sit, const char *name)
@@ -60,6 +61,7 @@ STAmount* STAmount::construct(SerializerIterator& sit, const char *name)
std::string STAmount::getRaw() const
{ // show raw internal form
if (value == 0) return "0";
return boost::lexical_cast<std::string>(value) + "e" + boost::lexical_cast<std::string>(offset);
}
@@ -116,8 +118,6 @@ bool STAmount::operator!=(const STAmount& a) const
bool STAmount::operator<(const STAmount& a) const
{
if (a.value == 0) return false;
if (value == 0) return true;
if (offset < a.offset) return true;
if (a.offset < offset) return false;
return value < a.value;
@@ -125,8 +125,6 @@ bool STAmount::operator<(const STAmount& a) const
bool STAmount::operator>(const STAmount& a) const
{
if (value == 0) return false;
if (a.value == 0) return true;
if (offset > a.offset) return true;
if (a.offset > offset) return false;
return value > a.value;
@@ -134,8 +132,6 @@ bool STAmount::operator>(const STAmount& a) const
bool STAmount::operator<=(const STAmount& a) const
{
if (value == 0) return true;
if (a.value == 0) return false;
if (offset < a.offset) return true;
if (a.offset < offset) return false;
return value <= a.value;
@@ -143,8 +139,6 @@ bool STAmount::operator<=(const STAmount& a) const
bool STAmount::operator>=(const STAmount& a) const
{
if (a.value == 0) return true;
if (value == 0) return false;
if (offset > a.offset) return true;
if (a.offset > offset) return false;
return value >= a.value;

View File

@@ -160,7 +160,7 @@ public:
class STAmount : public SerializedType
{
// Internal form:
// 1: If amount is zero, then offset and value are both zero.
// 1: If amount is zero, then value is zero and offset is -100
// 2: Otherwise:
// legal offset range is -96 to +80 inclusive
// value range is 10^15 to (10^16 - 1) inclusive
@@ -196,7 +196,7 @@ public:
int getOffset() const { return offset; }
uint64 getValue() const { return value; }
void zero() { offset=0; value=0; }
void zero() { offset=0; value=-100; }
bool isZero() const { return value==0; }
virtual bool isEquivalent(const SerializedType& t) const;