From ac202c199d241ccefac2f805730b63e121940618 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 31 Mar 2013 10:37:08 -0700 Subject: [PATCH] If an addition or subtraction has a microscopic amount left, make it zero. --- src/cpp/ripple/Amount.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 7546aa9cf..115fd9a36 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -799,7 +799,9 @@ STAmount operator+(const STAmount& v1, const STAmount& v2) // this addition cannot overflow an int64, it can overflow an STAmount and the constructor will throw int64 fv = vv1 + vv2; - if (fv >= 0) + if ((fv >= -10) && (fv <= 10)) + return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer); + else if (fv >= 0) return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, fv, ov1, false); else return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, -fv, ov1, true); @@ -834,7 +836,9 @@ STAmount operator-(const STAmount& v1, const STAmount& v2) // this subtraction cannot overflow an int64, it can overflow an STAmount and the constructor will throw int64 fv = vv1 - vv2; - if (fv >= 0) + if ((fv >= -10) && (fv <= 10)) + return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer); + else if (fv >= 0) return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, fv, ov1, false); else return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, -fv, ov1, true);