예제 #1
0
int main()
{
   check_placeholder(std::tr1::placeholders::_1);
   check_placeholder(std::tr1::placeholders::_2);
   check_placeholder(std::tr1::placeholders::_3);
   check_placeholder(std::tr1::placeholders::_4);
   check_placeholder(std::tr1::placeholders::_5);
   check_placeholder(std::tr1::placeholders::_6);
   check_placeholder(std::tr1::placeholders::_7);
   check_placeholder(std::tr1::placeholders::_8);
   check_placeholder(std::tr1::placeholders::_9);

   check_bind0(std::tr1::bind(&test_proc, 0, 0, 0), double(0));
   check_bind0(std::tr1::bind<double>(&test_proc, 0, 0, 0), double(0));
   check_bind1(std::tr1::bind(&test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
   check_bind1(std::tr1::bind(&test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);

   check_bind0(std::tr1::bind(test_proc, 0, 0, 0), double(0));
   check_bind0(std::tr1::bind<double>(test_proc, 0, 0, 0), double(0));
   check_bind1(std::tr1::bind(test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
   check_bind1(std::tr1::bind(test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);

   check_bind0(std::tr1::bind(std::plus<double>(), 0, 1), double(0));
   check_bind0(std::tr1::bind<double>(std::plus<double>(), 1, 0), double(0));
   check_bind0(std::tr1::bind<from_double>(std::plus<double>(), 1, 0), from_double(0));
   check_bind1(std::tr1::bind(std::plus<double>(), 0, std::tr1::placeholders::_1), double(0), 0);
   check_bind1(std::tr1::bind(std::plus<double>(), std::tr1::placeholders::_1, 0), double(0), 0);
   return 0;
}
예제 #2
0
static void from_double(mpq_t n, double f, int level)
{
    double fa;
    int nfa;
    mpq_t ni, nn;
    bool neg;

    //fprintf(stderr, "from_double: %.14g\n", f);

    if (level >= 10)
        goto __DEFAULT;

    fa = fabs(f);
    if (fa >= 1E8 || fa <= 1E-8)
        goto __DEFAULT;

    neg = (f < 0);

    nfa = (int)fa;
    if (nfa >= 1)
        fa -= nfa;

    //fprintf(stderr, "fa = %.14g %.14g\n", fa, (fa*1E8) - (int)(fa*1E8));

    if (nfa && fa < 1E-8)
    {
        mpq_set_si(n, 0, 1);
    }
    else if (((fa*1E8) - (int)(fa*1E8)) < 1E-8)
    {
        mpq_set_si(n, (int)(fa*1E8), 100000000);
    }
    else
    {
        mpq_init(ni);
        from_double(ni, 1 / fa, level + 1);
        mpq_inv(n, ni);
        mpq_clear(ni);
    }

    mpq_init(nn);
    mpq_set_si(nn, nfa, 1);
    mpq_add(n, n, nn);
    mpq_clear(nn);

    if (neg)
        mpq_neg(n, n);

    mpq_canonicalize(n);

    return;

__DEFAULT:

    mpq_set_d(n, f);
}
예제 #3
0
static void my_mpq_set_d(mpq_t n, double f)
{
    from_double(n, f, 0);
}
예제 #4
0
파일: decimal.hpp 프로젝트: saleyn/utxx
 /// Construct a decimal from a double.
 decimal(double x, uint precision)       { from_double(x, precision); }