Example #1
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

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

    flint_randinit(state);

    for (i = 0; i < 10000; i++)
    {
        fmpz_t p;
        long N;
        padic_ctx_t ctx;

        padic_t x;
        fmpq_t y;

        char *s, *t;

        fmpz_init(p);
        fmpz_set_ui(p, n_randprime(state, 5, 1));
        N = z_randint(state, 50) + 1;
        padic_ctx_init(ctx, p, N, PADIC_TERSE);

        padic_init(x, ctx);
        fmpq_init(y);

        padic_randtest(x, state, ctx);
        _padic_get_fmpq(y, x, ctx);

        s = _padic_get_str(NULL, x, ctx);
        t = fmpq_get_str(NULL, 10, y);

        result = strcmp(s, t) == 0;
        if (!result)
        {
            printf("FAIL:\n\n");
            printf("x = "), _padic_print(x, ctx), printf("\n");
            printf("y = "), fmpq_clear(y), printf("\n");
            abort();
        }

        free(s);
        free(t);
        _padic_clear(x);
        fmpq_clear(y);
        padic_ctx_clear(ctx);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #2
0
std::string renf_elem_class::to_string(int flags) const noexcept
{
    std::string s;

    assert(!((flags & EANTIC_STR_D) && (flags & EANTIC_STR_ARB)));

    // call to renf_elem_get_str_pretty
    if (nf == nullptr)
    {
        if (flags & EANTIC_STR_ALG)
        {
            char * u = fmpq_get_str(nullptr, 10, b);
            s += u;
            flint_free(u);

            if (flags & (EANTIC_STR_D | EANTIC_STR_ARB)) s += " ~ ";
        }
        if (flags & EANTIC_STR_D)
        {
            char * u = (char *) flint_malloc(20 * sizeof(char));
            sprintf(u, "%lf", fmpq_get_d(b));
            s += u;
            flint_free(u);
        }
        if (flags & EANTIC_STR_ARB)
        {
            char * u;
            arb_t x;
            arb_init(x);
            arb_set_fmpq(x, b, 128);
            u = arb_get_str(x, 64, 0);
            s += u;
            arb_clear(x);
            flint_free(u);
        }
    }
    else
    {
        char * u = renf_elem_get_str_pretty(renf_elem_t(), parent().gen_name().c_str(), parent().renf_t(), 10, flags);
        s += u;
        flint_free(u);
    }

    if (flags != EANTIC_STR_ALG && flags != EANTIC_STR_D && flags != EANTIC_STR_ARB)
        return "(" + s + ")";
    else
        return s;
}