Exemplo n.º 1
0
int
main(void)
{
    int i;
    FLINT_TEST_INIT(state);
    

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

    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, r;
        fmpz * c;
        slong n, bound;

        fmpq_init(x);
        fmpq_init(r);

        /* Test worst case (quotient of Fibonacci numbers) */
        if (n_randint(state, 50) == 1)
        {
            slong v = 1 + n_randint(state, 1000);
            fmpz_fib_ui(fmpq_numref(x), v + 1);
            fmpz_fib_ui(fmpq_denref(x), v);
        }
        else
        {
            fmpq_randtest(x, state, 1 + n_randint(state, 1000));
        }

        bound = fmpq_cfrac_bound(x);
        c = _fmpz_vec_init(bound + 10);
        n = fmpq_get_cfrac(c, r, x, bound);

        if (n > bound)
        {
            flint_printf("FAIL: length=%wd > bound=%wd\n", n, bound);
            abort();
        }

        _fmpz_vec_clear(c, bound + 10);
        fmpq_clear(x);
        fmpq_clear(r);
    }

    

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return 0;
}
Exemplo n.º 2
0
int
main(void)
{
    int i;
    flint_rand_t state;
    flint_randinit(state);

    printf("set_cfrac....");
    fflush(stdout);

    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, y, r;
        fmpz * c;
        long n, bound;

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(r);

        fmpq_randtest(x, state, 1 + n_randint(state, 1000));
        bound = fmpq_cfrac_bound(x);

        c = _fmpz_vec_init(bound);

        n = fmpq_get_cfrac(c, r, x, bound);
        fmpq_set_cfrac(y, c, n);

        if (!fmpq_equal(x, y))
        {
            printf("FAIL: x != y\n");
            printf("x = "); fmpq_print(x); printf("\n");
            printf("y = "); fmpq_print(y); printf("\n");
            printf("c = "); _fmpz_vec_print(c, n); printf("\n\n");
            abort();
        }

        _fmpz_vec_clear(c, bound);
        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(r);
    }

    flint_randclear(state);

    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}