From d663037ddcf42ba0254ffce687c5716c092e71bb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 30 Jan 2013 11:29:59 -0800 Subject: [PATCH] Report a rate of zero for worthless orders. --- src/cpp/ripple/Amount.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 347f3642c..91109a9da 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -995,11 +995,15 @@ STAmount STAmount::multiply(const STAmount& v1, const STAmount& v2, const uint16 // <-- uRate: normalize(offerIn/offerOut) // A lower rate is better for the person taking the order. // The taker gets more for less with a lower rate. +// Zero is returned if the offer is worthless. uint64 STAmount::getRate(const STAmount& offerOut, const STAmount& offerIn) { - if (offerOut.isZero()) throw std::runtime_error("Worthless offer"); + if (offerOut.isZero()) + return 0; STAmount r = divide(offerIn, offerOut, CURRENCY_ONE, ACCOUNT_ONE); + if (r.isZero()) + return 0; assert((r.getExponent() >= -100) && (r.getExponent() <= 155)); @@ -1010,6 +1014,9 @@ uint64 STAmount::getRate(const STAmount& offerOut, const STAmount& offerIn) STAmount STAmount::setRate(uint64 rate) { + if (rate == 0) + return STAmount(CURRENCY_ONE, ACCOUNT_ONE); + uint64 mantissa = rate & ~(255ull << (64 - 8)); int exponent = static_cast(rate >> (64 - 8)) - 100;