Exemple #1
0
    void
    test_raw()
    {
        testcase ("raw");

        {
            Quality q (0x5d048191fb9130daull);      // 126836389.7680090
            Amounts const value (
                amount(349469768),                  // 349.469768 XRP
                raw (2755280000000000ull, -15));    // 2.75528
            STAmount const limit (
                raw (4131113916555555, -16));       // .4131113916555555
            Amounts const result (q.ceil_out (value, limit));
            expect (result.in != zero);
        }
    }
Exemple #2
0
static
STAmount
qual_mul (STAmount const& amount, Quality const& quality, STAmount const& output)
{
    auto result = multiply (amount, quality.rate (), output.issue ());
    return std::min (result, output);
}
Exemple #3
0
    void
    ceil_out (Quality const& q,
        In1 in, Out1 out, Int limit, In2 in_expected, Out2 out_expected)
    {
        auto const expect_result (amounts (in_expected, out_expected));
        auto const actual_result (q.ceil_out (amounts(in, out), amount(limit)));

        expect (actual_result == expect_result);
    }
Exemple #4
0
Quality
composed_quality (Quality const& lhs, Quality const& rhs)
{
    Amount const lhs_rate (lhs.rate ());
    assert (lhs_rate != zero);

    Amount const rhs_rate (rhs.rate ());
    assert (rhs_rate != zero);

    Amount const rate (Amount::mulRound (lhs_rate, rhs_rate, true));

    std::uint64_t const stored_exponent (rate.getExponent () + 100);
    std::uint64_t const stored_mantissa (rate.getMantissa ());

    assert ((stored_exponent >= 0) && (stored_exponent <= 255));

    return Quality ((stored_exponent << (64 - 8)) | stored_mantissa);
}
Exemple #5
0
FullQuality<C>::FullQuality(const Quality& qual, const Sequence& seq) {
  this->length = MIN(qual.length(), seq.getSequenceLength());
  this->symbolCount = C::length();
  this->probVector = initProbMatrix(this->symbolCount, this->length);
  // get the probabilities vector
  double* probs = qual.getProbabilities();
  // loop through all elements
  for (size_t pos = 0; pos < this->length; ++pos) {
    // get the index for the actual symbol
    size_t symbolIndex = C::getIndex(seq.getBaseAt(pos));
    double remind_p = (probs[pos] ) / ((double)(this->symbolCount - 1));
    // loop through all symbols
    for (size_t sym = 0; sym < this->symbolCount; ++sym) {
      this->probVector[sym][pos] = remind_p;
    }
    this->probVector[symbolIndex][pos] = 1.0 - probs[pos];
  }
}
Exemple #6
0
    void
    ceil_in (Quality const& q,
        In1 in, Out1 out, Int limit, In2 in_expected, Out2 out_expected)
    {
        auto expect_result (amounts (in_expected, out_expected));
        auto actual_result (q.ceil_in (
            amounts (in, out), amount (limit)));

        BEAST_EXPECT(actual_result == expect_result);
    }
Exemple #7
0
Quality
composed_quality (Quality const& lhs, Quality const& rhs)
{
    STAmount const lhs_rate (lhs.rate ());
    assert (lhs_rate != zero);

    STAmount const rhs_rate (rhs.rate ());
    assert (rhs_rate != zero);

    STAmount const rate (mulRound (
        lhs_rate, rhs_rate, lhs_rate.issue (), true));

    std::uint64_t const stored_exponent (rate.exponent () + 100);
    std::uint64_t const stored_mantissa (rate.mantissa());

    assert ((stored_exponent > 0) && (stored_exponent <= 255));

    return Quality ((stored_exponent << (64 - 8)) | stored_mantissa);
}
Exemple #8
0
    void
    test_round()
    {
        testcase ("round");

        Quality q (0x59148191fb913522ull);      // 57719.63525051682
        BEAST_EXPECT(q.round(3).rate().getText() == "57800");
        BEAST_EXPECT(q.round(4).rate().getText() == "57720");
        BEAST_EXPECT(q.round(5).rate().getText() == "57720");
        BEAST_EXPECT(q.round(6).rate().getText() == "57719.7");
        BEAST_EXPECT(q.round(7).rate().getText() == "57719.64");
        BEAST_EXPECT(q.round(8).rate().getText() == "57719.636");
        BEAST_EXPECT(q.round(9).rate().getText() == "57719.6353");
        BEAST_EXPECT(q.round(10).rate().getText() == "57719.63526");
        BEAST_EXPECT(q.round(11).rate().getText() == "57719.635251");
        BEAST_EXPECT(q.round(12).rate().getText() == "57719.6352506");
        BEAST_EXPECT(q.round(13).rate().getText() == "57719.63525052");
        BEAST_EXPECT(q.round(14).rate().getText() == "57719.635250517");
        BEAST_EXPECT(q.round(15).rate().getText() == "57719.6352505169");
        BEAST_EXPECT(q.round(16).rate().getText() == "57719.63525051682");
    }