void evalNode(BigNumber &n, int i, DdValues<BigNumber, ARITY> const &values)
            {
                assert(size_t(i) <= pools.size());

                if (BDD) {
                    int w = tmp1.store(0);

                    for (int b = 0; b < ARITY; ++b) {
                        tmp2.store(values.get(b));
                        tmp2.shiftLeft(i - values.getLevel(b) - 1);
                        w = tmp1.add(tmp2);
                    }

                    n.setArray(pools[i].template allocate<uint64_t>(w));
                    n.store(tmp1);
                } else {
                    int w;

                    if (ARITY <= 0) {
                        w = tmp1.store(0);
                    } else {
                        w = tmp1.store(values.get(0));

                        for (int b = 1; b < ARITY; ++b) {
                            w = tmp1.add(values.get(b));
                        }
                    }

                    n.setArray(pools[i].template allocate<uint64_t>(w));
                    n.store(tmp1);
                }
            }
示例#2
0
 void evalNode(BigNumber& n,
               int i,
               DdValues<BigNumber,ARITY> const& values) {
     assert(0 <= i && size_t(i) <= pools.size());
     if (BDD) {
         size_t w = tmp1.store(0);
         for (int b = 0; b < ARITY; ++b) {
             tmp2.store(values.get(b));
             int k = i - values.getLevel(b) - 1;
             if (ARITY == 2) {
                 tmp2.shiftLeft(k);
             }
             else {
                 while (--k >= 0) {
                     tmp3.store(tmp2);
                     for (int b = 1; b < ARITY; ++b) {
                         tmp2.add(tmp3);
                     }
                 }
             }
             w = tmp1.add(tmp2);
         }
         n.setArray(pools[i].allocate<uint64_t>(w));
         n.store(tmp1);
     }
     else {
         size_t w;
         if (ARITY <= 0) {
             w = tmp1.store(0);
         }
         else {
             w = tmp1.store(values.get(0));
             for (int b = 1; b < ARITY; ++b) {
                 w = tmp1.add(values.get(b));
             }
         }
         n.setArray(pools[i].allocate<uint64_t>(w));
         n.store(tmp1);
     }
 }
示例#3
0
int main() {
    assert(BigNumber(6, 9).toString() == "6.9");
    assert(BigNumber(3).toString() == "3");
    assert(BigNumber(-5).toString() == "-5");

    vector<string> v = {"10", "10.3", "-10.555", "69.34433434", "0", "2"};

    for (int i = 0; i < v.size(); i++)
        assert(BigNumber(v[i]).toString() == v[i]);


    BigNumber nineteen = BigNumber(19);
    nineteen.plus_one();
    assert(nineteen.toString() == "20");

    BigNumber x = BigNumber(8);
    x.plus_one();
    assert(x.toString() == "9");
    x.plus_one();
    assert(x.toString() == "10");
    BigNumber y = BigNumber("10.6");
    y.plus_one();
    assert(y.toString() == "11.6");

    BigNumber ten = BigNumber("5.1");
    ten.add(BigNumber("3.2"));
    assert(ten.toString() == "8.3");
    ten.add(BigNumber("1.12"));
    assert(ten.toString() == "9.42");
    ten.add(BigNumber("0.1"));
    assert(ten.toString() == "9.52");
    ten.add(BigNumber("0.000001"));
    assert(ten.toString() == "9.520001");

    return 0;
}
示例#4
0
BigNumber solve(int l, int b, int p) {
    for (int i = 0; i <= l; ++i)
        for (int j = 0; j <= p; ++j)
            dp[i][j] = BigNumberZ;
 
    dp[1][0] = BigNumber(b);
    for (int i = 2; i <= l; ++i) {
        for (int k = 0; k <= p; ++k) {
            dp[i][0].add(dp[i - 1][k] * b);
            if (k != 0)
                dp[i][k] = dp[i - 1][k - 1];
        }
    }
    BigNumber rez;
        for (int k = 0; k <= p; ++k)
            rez.add(dp[l][k]);   
    return rez;
}
示例#5
0
 std::string getValue(BigNumber const& n) {
     if (BDD) {
         tmp2.store(n);
         int k = numVars - topLevel;
         if (ARITY == 2) {
             tmp2.shiftLeft(k);
         }
         else {
             while (--k >= 0) {
                 tmp3.store(tmp2);
                 for (int b = 1; b < ARITY; ++b) {
                     tmp2.add(tmp3);
                 }
             }
         }
         return tmp2;
     }
     else {
         return n;
     }
 }