int arf_add_naive(arf_t z, const arf_t x, const arf_t y, slong prec, arf_rnd_t rnd) { if (rnd == ARF_RND_NEAR) { arf_add(z, x, y, ARF_PREC_EXACT, ARF_RND_DOWN); return arf_set_round(z, z, prec, rnd); } else { fmpr_t a, b; slong r; fmpr_init(a); fmpr_init(b); arf_get_fmpr(a, x); arf_get_fmpr(b, y); r = fmpr_add(a, a, b, prec, rnd); arf_set_fmpr(z, a); fmpr_clear(a); fmpr_clear(b); return (r == FMPR_RESULT_EXACT) ? 0 : 1; } }
void zeta_series_em_choose_param(fmpr_t bound, ulong * N, ulong * M, const fmpcb_t s, const fmpcb_t a, long d, long target, long prec) { ulong A, B, C; fmpr_t Abound, Bbound, Cbound, tol; fmpr_init(Abound); fmpr_init(Bbound); fmpr_init(Cbound); fmpr_init(tol); fmpr_set_si_2exp_si(tol, 1, -target); A = 1; B = 2; zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec); if (fmpr_cmp(Bbound, tol) > 0) { while (fmpr_cmp(Bbound, tol) > 0) { fmpr_set(Abound, Bbound); A *= 2; B *= 2; if (B == 0) abort(); zeta_series_em_bound(Bbound, s, a, B, choose_M(B, target), d, prec); } /* bisect (-A, B] */ while (B > A + 4) { C = A + (B - A) / 2; zeta_series_em_bound(Cbound, s, a, C, choose_M(C, target), d, prec); if (fmpr_cmp(Cbound, tol) < 0) { B = C; fmpr_set(Bbound, Cbound); } else { A = C; fmpr_set(Abound, Cbound); } } } fmpr_set(bound, Bbound); *N = B; *M = choose_M(B, target); fmpr_clear(Abound); fmpr_clear(Bbound); fmpr_clear(Cbound); fmpr_clear(tol); }
void fmprb_mul_main_naive(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec) { if (fmpr_is_pos_inf(fmprb_radref(x)) || fmpr_is_pos_inf(fmprb_radref(y))) { fmpr_mul(fmprb_midref(z), fmprb_midref(x), fmprb_midref(y), prec, FMPR_RND_DOWN); fmpr_pos_inf(fmprb_radref(z)); } else { fmpr_t t, u; slong r; fmpr_init(t); fmpr_init(u); /* (x+a)*(y+b) = x*y + x*b + y*a + a*b*/ fmpr_mul(t, fmprb_midref(x), fmprb_radref(y), FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_abs(t, t); fmpr_mul(u, fmprb_midref(y), fmprb_radref(x), FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_abs(u, u); fmpr_add(t, t, u, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_addmul(t, fmprb_radref(x), fmprb_radref(y), FMPRB_RAD_PREC, FMPR_RND_UP); r = fmpr_mul(fmprb_midref(z), fmprb_midref(x), fmprb_midref(y), prec, FMPR_RND_DOWN); fmpr_add_error_result(fmprb_radref(z), t, fmprb_midref(z), r, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_clear(t); fmpr_clear(u); } }
void gamma_taylor_bound_remainder(fmpr_t err, const fmpr_t z, long n) { fmpr_t t, u; gamma_taylor_bound_extend_cache(n + 1); fmpr_init(t); fmpr_init(u); /* denominator: 1 - r(n+1) * z, rounded down */ fmpr_mul(t, gamma_taylor_bound_ratio_cache + n + 1, z, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_one(u); fmpr_sub(u, u, t, FMPRB_RAD_PREC, FMPR_RND_DOWN); if (fmpr_sgn(u) <= 0) { fmpr_pos_inf(err); } else { fmpr_pow_sloppy_ui(t, z, n, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_mul_2exp_si(t, t, gamma_taylor_bound_mag_cache[n + 1]); fmpr_div(err, t, u, FMPRB_RAD_PREC, FMPR_RND_UP); } fmpr_clear(t); fmpr_clear(u); }
void fmpcb_mat_bound_inf_norm(fmpr_t b, const fmpcb_mat_t A, long prec) { long i, j, r, c; fmpr_t s, t; r = fmpcb_mat_nrows(A); c = fmpcb_mat_ncols(A); fmpr_zero(b); if (r == 0 || c == 0) return; fmpr_init(s); fmpr_init(t); for (i = 0; i < r; i++) { fmpr_zero(s); for (j = 0; j < c; j++) { fmpcb_get_abs_ubound_fmpr(t, fmpcb_mat_entry(A, i, j), prec); fmpr_add(s, s, t, prec, FMPR_RND_UP); } fmpr_max(b, b, s); } fmpr_clear(s); fmpr_clear(t); }
int main() { slong iter; flint_rand_t state; flint_printf("set_d...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { fmpr_t a, b, c; mag_t m; double x; fmpr_init(a); fmpr_init(b); fmpr_init(c); mag_init(m); x = d_randtest2(state); x = ldexp(x, 100 - n_randint(state, 200)); if (n_randint(state, 100) == 0) x = 0.0; fmpr_set_d(a, x); mag_set_d(m, x); mag_get_fmpr(b, m); fmpr_set(c, a); fmpr_mul_ui(c, c, 1025, MAG_BITS, FMPR_RND_UP); fmpr_mul_2exp_si(c, c, -10); MAG_CHECK_BITS(m) if (!(fmpr_cmpabs(a, b) <= 0 && fmpr_cmpabs(b, c) <= 0)) { flint_printf("FAIL\n\n"); flint_printf("a = "); fmpr_print(a); flint_printf("\n\n"); flint_printf("b = "); fmpr_print(b); flint_printf("\n\n"); flint_printf("c = "); fmpr_print(c); flint_printf("\n\n"); abort(); } fmpr_clear(a); fmpr_clear(b); fmpr_clear(c); mag_clear(m); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("cmpabs...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { slong bits; fmpr_t x, y; mpfr_t X, Y; int cmp1, cmp2; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(y); mpfr_init2(X, bits); mpfr_init2(Y, bits); fmpr_randtest_special(x, state, bits, 10); fmpr_randtest_special(y, state, bits, 10); fmpr_get_mpfr(X, x, MPFR_RNDN); fmpr_get_mpfr(Y, y, MPFR_RNDN); mpfr_abs(X, X, MPFR_RNDN); mpfr_abs(Y, Y, MPFR_RNDN); cmp1 = fmpr_cmpabs(x, y); cmp2 = mpfr_cmp(X, Y); if (cmp1 != cmp2) { flint_printf("FAIL\n\n"); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("cmp1 = %d, cmp2 = %d\n\n", cmp1, cmp2); abort(); } fmpr_clear(x); fmpr_clear(y); mpfr_clear(X); mpfr_clear(Y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("mul_2exp_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { fmpr_t x, y, z; mag_t xb, yb; slong e; fmpr_init(x); fmpr_init(y); fmpr_init(z); mag_init(xb); mag_init(yb); mag_randtest_special(xb, state, 100); e = z_randtest(state); mag_get_fmpr(x, xb); mag_mul_2exp_si(yb, xb, e); fmpr_mul_2exp_si(y, x, e); mag_get_fmpr(z, yb); MAG_CHECK_BITS(yb) if (!fmpr_equal(z, y)) { flint_printf("FAIL\n\n"); flint_printf("x = "); fmpr_printd(x, 15); flint_printf("\n\n"); flint_printf("y = "); fmpr_printd(y, 15); flint_printf("\n\n"); flint_printf("z = "); fmpr_printd(z, 15); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(y); fmpr_clear(z); mag_clear(xb); mag_clear(yb); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_fmpq...."); fflush(stdout); flint_randinit(state); /* test exact roundtrip R -> Q -> R */ for (iter = 0; iter < 100000; iter++) { slong bits, res; fmpr_t x, z; fmpq_t y; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(z); fmpq_init(y); fmpr_randtest(x, state, bits, 10); fmpr_randtest(z, state, bits, 10); fmpr_get_fmpq(y, x); res = fmpr_set_fmpq(z, y, bits, FMPR_RND_DOWN); if (!fmpr_equal(x, z) || !fmpr_check_ulp(z, res, bits)) { flint_printf("FAIL\n\n"); flint_printf("bits: %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(z); fmpq_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("binpow_uiui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { fmpr_t x, y; mag_t b; ulong m, n; fmpr_init(x); fmpr_init(y); mag_init(b); m = n_randtest(state); n = n_randtest(state); fmpr_one(x); fmpr_div_ui(x, x, m, 128, FMPR_RND_UP); fmpr_add_ui(x, x, 1, 128, FMPR_RND_UP); fmpr_pow_sloppy_ui(x, x, n, 128, FMPR_RND_UP); mag_binpow_uiui(b, m, n); mag_get_fmpr(y, b); MAG_CHECK_BITS(b) if (!(fmpr_cmpabs(x, y) <= 0)) { flint_printf("FAIL\n\n"); flint_printf("m = %wu\n\n", m); flint_printf("n = %wu\n\n", n); flint_printf("x = "); fmpr_printd(x, 10); flint_printf("\n\n"); flint_printf("y = "); fmpr_printd(y, 10); flint_printf("\n\n"); flint_abort(); } fmpr_clear(x); fmpr_clear(y); mag_clear(b); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("cmp...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { fmpr_t x, y; mag_t xb, yb; int c1, c2; fmpr_init(x); fmpr_init(y); mag_init(xb); mag_init(yb); mag_randtest_special(xb, state, 100); mag_randtest_special(yb, state, 100); mag_get_fmpr(x, xb); mag_get_fmpr(y, yb); c1 = fmpr_cmp(x, y); c2 = mag_cmp(xb, yb); if (c1 != c2) { flint_printf("FAIL\n\n"); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("xb = "); mag_print(xb); flint_printf("\n\n"); flint_printf("yb = "); mag_print(yb); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(y); mag_clear(xb); mag_clear(yb); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("rfac_ui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++) { fmpr_t x, y; fmpz_t f; mag_t xb; ulong n; fmpr_init(x); fmpr_init(y); fmpz_init(f); mag_init(xb); mag_randtest_special(xb, state, 80); n = n_randtest(state) % 2000; mag_rfac_ui(xb, n); fmpz_fac_ui(f, n); fmpr_one(x); fmpr_div_fmpz(x, x, f, 2 * MAG_BITS, FMPR_RND_UP); mag_get_fmpr(y, xb); MAG_CHECK_BITS(xb) if (!(fmpr_cmpabs(y, x) >= 0)) { flint_printf("FAIL\n\n"); flint_printf("n = %wu\n\n", n); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(y); fmpz_clear(f); mag_clear(xb); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_fmpz_2exp...."); fflush(stdout); flint_randinit(state); /* test exact roundtrip R -> Q -> R */ for (iter = 0; iter < 100000; iter++) { slong bits; fmpr_t x, z; fmpz_t y, e; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(z); fmpz_init(y); fmpz_init(e); fmpr_randtest(x, state, bits, 10); fmpr_randtest(z, state, bits, 10); fmpr_get_fmpz_2exp(y, e, x); fmpr_set_fmpz_2exp(z, y, e); if (!fmpr_equal(x, z)) { flint_printf("FAIL\n\n"); flint_printf("bits: %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpz_print(y); flint_printf("\n\n"); flint_printf("e = "); fmpz_print(e); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(z); fmpz_clear(y); fmpz_clear(e); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
slong fmpr_fmpz_div_fmpz(fmpr_t z, const fmpz_t x, const fmpz_t y, slong prec, fmpr_rnd_t rnd) { fmpr_t t, u; slong r; fmpr_init(t); fmpr_init(u); fmpr_set_fmpz(t, x); fmpr_set_fmpz(u, y); r = fmpr_div(z, t, u, prec, rnd); fmpr_clear(t); fmpr_clear(u); return r; }
static __inline__ void fmpcb_inv_mid(fmpcb_t z, const fmpcb_t x, long prec) { fmpr_t t; fmpr_init(t); #define a fmprb_midref(fmpcb_realref(x)) #define b fmprb_midref(fmpcb_imagref(x)) #define e fmprb_midref(fmpcb_realref(z)) #define f fmprb_midref(fmpcb_imagref(z)) fmpr_mul(t, a, a, prec, FMPR_RND_DOWN); fmpr_addmul(t, b, b, prec, FMPR_RND_DOWN); fmpr_div(e, a, t, prec, FMPR_RND_DOWN); fmpr_div(f, b, t, prec, FMPR_RND_DOWN); fmpr_neg(f, f); #undef a #undef b #undef e #undef f fmpr_clear(t); }
void fmprb_sqrt(fmprb_t z, const fmprb_t x, slong prec) { slong r; if (fmprb_contains_negative(x)) { fmpr_nan(fmprb_midref(z)); fmpr_pos_inf(fmprb_radref(z)); return; } if (fmprb_is_exact(x)) { r = fmpr_sqrt(fmprb_midref(z), fmprb_midref(x), prec, FMPR_RND_DOWN); fmpr_set_error_result(fmprb_radref(z), fmprb_midref(z), r); } else { fmpr_t err; fmpr_init(err); fmpr_sub(err, fmprb_midref(x), fmprb_radref(x), FMPRB_RAD_PREC, FMPR_RND_DOWN); fmpr_rsqrt(err, err, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_mul(err, fmprb_radref(x), err, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_mul_2exp_si(err, err, -1); r = fmpr_sqrt(fmprb_midref(z), fmprb_midref(x), prec, FMPR_RND_DOWN); fmpr_add_error_result(fmprb_radref(z), err, fmprb_midref(z), r, FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_clear(err); } fmprb_adjust(z); }
int main() { slong iter; flint_rand_t state; flint_printf("cmp_2exp_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { slong bits, e; fmpr_t x, y; int cmp1, cmp2; bits = 2 + n_randint(state, 1000); e = n_randtest(state); fmpr_init(x); fmpr_init(y); fmpr_randtest_special(x, state, bits, 100); fmpr_set_ui_2exp_si(y, 1, e); cmp1 = fmpr_cmp(x, y); cmp2 = fmpr_cmp_2exp_si(x, e); if (cmp1 != cmp2) { flint_printf("FAIL\n\n"); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("cmp1 = %d, cmp2 = %d\n\n", cmp1, cmp2); abort(); } fmpr_clear(x); fmpr_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void fmprb_hypgeom_infsum(fmprb_t P, fmprb_t Q, hypgeom_t hyp, long target_prec, long prec) { mag_t err, z; long n; mag_init(err); mag_init(z); mag_set_fmpz(z, hyp->P->coeffs + hyp->P->length - 1); mag_div_fmpz(z, z, hyp->Q->coeffs + hyp->Q->length - 1); if (!hyp->have_precomputed) { hypgeom_precompute(hyp); hyp->have_precomputed = 1; } n = hypgeom_bound(err, hyp->r, hyp->boundC, hyp->boundD, hyp->boundK, hyp->MK, z, target_prec); fmprb_hypgeom_sum(P, Q, hyp, n, prec); if (fmpr_sgn(fmprb_midref(Q)) < 0) { fmprb_neg(P, P); fmprb_neg(Q, Q); } /* We have p/q = s + err i.e. (p + q*err)/q = s */ { fmpr_t u, v; fmpr_init(u); fmpr_init(v); mag_get_fmpr(v, err); fmpr_add(u, fmprb_midref(Q), fmprb_radref(Q), FMPRB_RAD_PREC, FMPR_RND_UP); fmpr_mul(u, u, v, FMPRB_RAD_PREC, FMPR_RND_UP); fmprb_add_error_fmpr(P, u); fmpr_clear(u); fmpr_clear(v); } mag_clear(z); mag_clear(err); }
void fmprb_add_error_2exp_si(fmprb_t x, slong err) { fmpr_t t; fmpr_init(t); fmpr_set_ui_2exp_si(t, 1, err); fmprb_add_error_fmpr(x, t); fmpr_clear(t); }
int main() { long iter; flint_rand_t state; printf("set_interval_fmpr...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { fmprb_t x; fmpr_t a, b; fmprb_init(x); fmpr_init(a); fmpr_init(b); fmpr_randtest_special(a, state, 200, 10); fmpr_randtest_special(b, state, 200, 10); if (fmpr_cmp(a, b) > 0) fmpr_swap(a, b); fmprb_set_interval_fmpr(x, a, b, 2 + n_randint(state, 200)); if (!fmprb_contains_fmpr(x, a) || !fmprb_contains_fmpr(x, b)) { printf("FAIL:\n\n"); printf("x = "); fmprb_print(x); printf("\n\n"); printf("a = "); fmpr_print(a); printf("\n\n"); printf("b = "); fmpr_print(b); printf("\n\n"); abort(); } fmprb_clear(x); fmpr_clear(a); fmpr_clear(b); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("get_mpfr...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong bits; fmpr_t x, z; mpfr_t y; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(z); mpfr_init2(y, bits); fmpr_randtest_special(x, state, bits, 10); fmpr_get_mpfr(y, x, MPFR_RNDN); fmpr_set_mpfr(z, y); if (!fmpr_equal(x, z)) { flint_printf("FAIL\n\n"); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_abort(); } fmpr_clear(x); fmpr_clear(z); mpfr_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
slong fmpr_si_div(fmpr_t z, slong x, const fmpr_t y, slong prec, fmpr_rnd_t rnd) { fmpr_t t; slong r; fmpr_init(t); fmpr_set_si(t, x); r = fmpr_div(z, t, y, prec, rnd); fmpr_clear(t); return r; }
void fmprb_add_error_2exp_fmpz(fmprb_t x, const fmpz_t err) { fmpr_t t; fmpr_init(t); fmpz_one(fmpr_manref(t)); fmpz_set(fmpr_expref(t), err); fmprb_add_error_fmpr(x, t); fmpr_clear(t); }
slong fmpr_add_si(fmpr_t z, const fmpr_t x, slong y, slong prec, fmpr_rnd_t rnd) { fmpr_t t; slong r; fmpr_init(t); fmpr_set_si(t, y); r = fmpr_add(z, x, t, prec, rnd); fmpr_clear(t); return r; }
static slong fmpr_mul_si_naive(fmpr_t z, const fmpr_t x, slong y, slong prec, fmpr_rnd_t rnd) { fmpr_t t; slong r; fmpr_init(t); fmpr_set_si(t, y); r = fmpr_mul(z, x, t, prec, rnd); fmpr_clear(t); return r; }
slong fmpr_submul_fmpz(fmpr_t z, const fmpr_t x, const fmpz_t y, slong prec, fmpr_rnd_t rnd) { fmpr_t t; slong r; fmpr_init(t); fmpr_set_fmpz(t, y); r = fmpr_submul(z, x, t, prec, rnd); fmpr_clear(t); return r; }
slong fmpr_rsqrt(fmpr_t y, const fmpr_t x, slong prec, fmpr_rnd_t rnd) { slong r; if (fmpr_is_special(x)) { if (fmpr_is_zero(x)) fmpr_pos_inf(y); else if (fmpr_is_pos_inf(x)) fmpr_zero(y); else fmpr_nan(y); return FMPR_RESULT_EXACT; } if (fmpr_sgn(x) < 0) { fmpr_nan(y); return FMPR_RESULT_EXACT; } /* special case: 4^n */ if (fmpz_is_one(fmpr_manref(x)) && fmpz_is_even(fmpr_expref(x))) { r = fmpr_set_round(y, x, prec, rnd); fmpz_tdiv_q_2exp(fmpr_expref(y), fmpr_expref(y), 1); fmpz_neg(fmpr_expref(y), fmpr_expref(y)); return r; } { fmpr_t t; fmpz_t e; fmpr_init(t); fmpz_init(e); fmpz_neg(e, fmpr_expref(x)); if (fmpz_is_odd(e)) fmpz_add_ui(e, e, 1); fmpr_mul_2exp_fmpz(t, x, e); CALL_MPFR_FUNC(r, mpfr_rec_sqrt, y, t, prec, rnd); fmpz_tdiv_q_2exp(e, e, 1); fmpr_mul_2exp_fmpz(y, y, e); fmpr_clear(t); fmpz_clear(e); return r; } }
int fmprb_contains_si(const fmprb_t x, long y) { int ans; fmpr_t t; fmpr_init(t); fmpr_set_si(t, y); ans = fmprb_contains_fmpr(x, t); fmpr_clear(t); return ans; }
slong fmpr_submul(fmpr_t z, const fmpr_t x, const fmpr_t y, slong prec, fmpr_rnd_t rnd) { fmpr_t t; slong r; fmpr_init(t); fmpr_mul(t, x, y, FMPR_PREC_EXACT, FMPR_RND_DOWN); r = fmpr_sub(z, z, t, prec, rnd); fmpr_clear(t); return r; }
int arf_mul_naive(arf_t z, const arf_t x, const arf_t y, long prec, arf_rnd_t rnd) { fmpr_t a, b; long r; fmpr_init(a); fmpr_init(b); arf_get_fmpr(a, x); arf_get_fmpr(b, y); r = fmpr_mul_naive(a, a, b, prec, rnd); arf_set_fmpr(z, a); fmpr_clear(a); fmpr_clear(b); return (r == FMPR_RESULT_EXACT) ? 0 : 1; }