Ejemplo n.º 1
0
int
arb_contains_arf(const arb_t x, const arf_t y)
{
    if (arf_is_nan(y))
    {
        return arf_is_nan(arb_midref(x));
    }
    else if (arf_is_nan(arb_midref(x)))
    {
        return 1;
    }
    else if (arb_is_exact(x))
    {
        return arf_equal(arb_midref(x), y);
    }
    else
    {
        arf_t t;
        arf_struct tmp[3];
        int result;

        arf_init(t);

        /* y >= xm - xr  <=>  0 >= xm - xr - y */
        arf_init_set_shallow(tmp + 0, arb_midref(x));
        arf_init_neg_mag_shallow(tmp + 1,  arb_radref(x));
        arf_init_neg_shallow(tmp + 2, y);

        arf_sum(t, tmp, 3, MAG_BITS, ARF_RND_DOWN);
        result = (arf_sgn(t) <= 0);

        if (result)
        {
            /* y <= xm + xr  <=>  0 <= xm + xr - y */
            arf_init_set_mag_shallow(tmp + 1,  arb_radref(x));
            arf_sum(t, tmp, 3, MAG_BITS, ARF_RND_DOWN);
            result = (arf_sgn(t) >= 0);
        }

        arf_clear(t);

        return result;
    }
}
Ejemplo n.º 2
0
Archivo: t-floor.c Proyecto: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("floor....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        arf_t x, y;
        int result;

        arf_init(x);
        arf_init(y);

        arf_randtest_special(x, state, 2000, 100);
        arf_randtest_special(y, state, 2000, 100);

        arf_floor(y, x);

        result = 1;

        if (arf_is_int(x) || !arf_is_finite(x))
        {
            result = arf_equal(y, x);
        }
        else if (!arf_is_int(y))
        {
            result = 0;
        }
        else if (arf_cmp(y, x) >= 0)
        {
            result = 0;
        }
        else
        {
            arf_t s, t[3];

            /* check floor(x) - x + 1 > 0 */

            arf_init(s);
            arf_init(t[0]);
            arf_init(t[1]);
            arf_init(t[2]);

            arf_set(t[0], y);
            arf_neg(t[1], x);
            arf_one(t[2]);

            arf_sum(s, (arf_ptr) t, 3, 32, ARF_RND_DOWN);

            result = arf_sgn(s) > 0;

            arf_clear(s);
            arf_clear(t[0]);
            arf_clear(t[1]);
            arf_clear(t[2]);
        }

        if (!result)
        {
            flint_printf("FAIL!\n");
            flint_printf("x = "); arf_print(x); flint_printf("\n\n");
            flint_printf("y = "); arf_print(y); flint_printf("\n\n");
            abort();
        }

        arf_floor(x, x);

        if (!arf_equal(x, y))
        {
            flint_printf("FAIL (aliasing)!\n");
            flint_printf("x = "); arf_print(x); flint_printf("\n\n");
            flint_printf("y = "); arf_print(y); flint_printf("\n\n");
            abort();
        }

        arf_clear(x);
        arf_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("sum....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++)
    {
        slong i, len, prec, bits, expbits;
        int res1, res2;
        arf_t s1, s2, s3, err;
        mag_t err_bound;
        arf_struct terms[20];
        arf_rnd_t rnd;

        len = n_randint(state, 20);
        bits = 2 + n_randint(state, 1000);
        prec = 2 + n_randint(state, 1000);
        expbits = n_randint(state, 14);

        arf_init(s1);
        arf_init(s2);
        arf_init(s3);
        arf_init(err);
        mag_init(err_bound);

        for (i = 0; i < len; i++)
        {
            arf_init(terms + i);
            arf_randtest_special(terms + i, state, bits, expbits);
        }

        switch (n_randint(state, 4))
        {
            case 0: rnd = ARF_RND_DOWN; break;
            case 1: rnd = ARF_RND_UP; break;
            case 2: rnd = ARF_RND_FLOOR; break;
            default: rnd = ARF_RND_CEIL; break;
        }

        res1 = arf_sum(s1, terms, len, prec, rnd);

        arf_zero(s2);
        for (i = 0; i < len; i++)
            arf_add(s2, s2, terms + i, ARF_PREC_EXACT, ARF_RND_DOWN);
        res2 = arf_set_round(s3, s2, prec, rnd);

        if (!arf_equal(s1, s3) || res1 != res2)
        {
            flint_printf("FAIL (%wd)\n\n", iter);
            flint_printf("prec = %wd\n\n", prec);
            for (i = 0; i < len; i++)
            {
                flint_printf("terms[%wd] = ", i); arf_print(terms + i); flint_printf("\n\n");
            }
            flint_printf("s1 = "); arf_print(s1); flint_printf("\n\n");
            flint_printf("s2 = "); arf_print(s2); flint_printf("\n\n");
            flint_printf("s3 = "); arf_print(s3); flint_printf("\n\n");
            flint_printf("res1 = %d, res2 = %d\n\n", res1, res2);
            abort();
        }

        arf_sub(err, s1, s2, ARF_PREC_EXACT, ARF_RND_DOWN);
        arf_abs(err, err);

        if (res1)
            arf_mag_set_ulp(err_bound, s1, prec);
        else
            mag_zero(err_bound);

        if (arf_cmpabs_mag(err, err_bound) > 0)
        {
            flint_printf("FAIL (error bound)!\n");
            flint_printf("prec = %wd\n\n", prec);
            for (i = 0; i < len; i++)
            {
                flint_printf("terms[%wd] = ", i); arf_print(terms + i); flint_printf("\n\n");
            }
            flint_printf("s1 = "); arf_print(s1); flint_printf("\n\n");
            flint_printf("s2 = "); arf_print(s2); flint_printf("\n\n");
            flint_printf("s3 = "); arf_print(s3); flint_printf("\n\n");
            flint_printf("error: "); arf_print(err); flint_printf("\n\n");
            flint_printf("error bound: "); mag_print(err_bound); flint_printf("\n\n");
            flint_printf("res1 = %d, res2 = %d\n\n", res1, res2);
            abort();
        }

        arf_clear(s1);
        arf_clear(s2);
        arf_clear(s3);
        arf_clear(err);
        mag_clear(err_bound);

        for (i = 0; i < len; i++)
            arf_clear(terms + i);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}