int main() { slong iter; flint_rand_t state; flint_printf("set_interval_mpfr...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { arb_t x; arf_t a, b; mpfr_t aa, bb; arb_init(x); arf_init(a); arf_init(b); mpfr_init2(aa, 200); mpfr_init2(bb, 200); arf_randtest_special(a, state, 200, 10); arf_randtest_special(b, state, 200, 10); if (arf_cmp(a, b) > 0) arf_swap(a, b); arf_get_mpfr(aa, a, MPFR_RNDD); arf_get_mpfr(bb, b, MPFR_RNDU); arb_set_interval_mpfr(x, aa, bb, 2 + n_randint(state, 200)); if (!arb_contains_arf(x, a) || !arb_contains_arf(x, b)) { flint_printf("FAIL:\n\n"); flint_printf("x = "); arb_print(x); flint_printf("\n\n"); flint_printf("a = "); arf_print(a); flint_printf("\n\n"); flint_printf("b = "); arf_print(b); flint_printf("\n\n"); abort(); } arb_clear(x); arf_clear(a); arf_clear(b); mpfr_clear(aa); mpfr_clear(bb); } flint_randclear(state); flint_cleanup(); flint_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 < 100000; iter++) { slong bits; arf_t x, z; mpfr_t y; bits = 2 + n_randint(state, 200); arf_init(x); arf_init(z); mpfr_init2(y, bits); arf_randtest_special(x, state, bits, 10); arf_get_mpfr(y, x, MPFR_RNDN); arf_set_mpfr(z, y); if (!arf_equal(x, z)) { flint_printf("FAIL\n\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); abort(); } arf_clear(x); arf_clear(z); 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("cmpabs...."); fflush(stdout); flint_randinit(state); /* compare with fmpz */ { arf_t x, y; fmpz_t X, Y; arf_init(x); arf_init(y); fmpz_init(X); fmpz_init(Y); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { int cmp1, cmp2; fmpz_randtest(X, state, 1 + n_randint(state, 1000)); switch (n_randint(state, 8)) { case 0: fmpz_neg(Y, X); break; case 1: fmpz_set(Y, X); break; default: fmpz_randtest(Y, state, 1 + n_randint(state, 1000)); } arf_set_fmpz(x, X); arf_set_fmpz(y, Y); cmp1 = arf_cmpabs(x, y); cmp2 = fmpz_cmpabs(X, Y); cmp2 = (cmp2 > 0) - (cmp2 < 0); if (cmp1 != cmp2) { flint_printf("FAIL\n\n"); flint_printf("x = "); arf_debug(x); flint_printf("\n\n"); flint_printf("y = "); arf_debug(y); flint_printf("\n\n"); flint_printf("X = "); fmpz_print(X); flint_printf("\n\n"); flint_printf("Y = "); fmpz_print(Y); flint_printf("\n\n"); flint_printf("cmp1 = %d, cmp2 = %d\n\n", cmp1, cmp2); abort(); } } arf_clear(x); arf_clear(y); fmpz_clear(X); fmpz_clear(Y); } /* compare with mpfr */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits; arf_t x, y; mpfr_t X, Y; int cmp1, cmp2; bits = 2 + n_randint(state, 200); arf_init(x); arf_init(y); mpfr_init2(X, bits); mpfr_init2(Y, bits); arf_randtest_special(x, state, bits, 10); arf_randtest_special(y, state, bits, 10); arf_get_mpfr(X, x, MPFR_RNDN); arf_get_mpfr(Y, y, MPFR_RNDN); mpfr_abs(X, X, MPFR_RNDN); mpfr_abs(Y, Y, MPFR_RNDN); cmp1 = arf_cmpabs(x, y); cmp2 = mpfr_cmp(X, Y); if (cmp1 != cmp2) { flint_printf("FAIL\n\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("cmp1 = %d, cmp2 = %d\n\n", cmp1, cmp2); abort(); } arf_clear(x); arf_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("is_int_2exp_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arf_t x, y; fmpz_t t; slong e; int res1, res2; arf_init(x); arf_init(y); fmpz_init(t); arf_randtest_special(x, state, 2000, 100); e = n_randtest(state); arf_mul_2exp_si(y, x, e); res1 = arf_is_int(x); res2 = arf_is_int_2exp_si(y, e); if (res1 != res2) { flint_printf("FAIL! (1)\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("res1 = %d, res2 = %d\n\n", res1, res2); abort(); } if (res1) { if (n_randint(state, 2)) arf_floor(y, x); else arf_ceil(y, x); if (!arf_equal(x, y) || !arf_is_finite(x)) { flint_printf("FAIL! (2)\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("res1 = %d\n\n", res1); abort(); } } if (arf_is_finite(x) && !arf_is_zero(x)) { arf_bot(t, x); fmpz_neg(t, t); arf_mul_2exp_fmpz(x, x, t); res1 = arf_is_int(x); arf_mul_2exp_si(y, x, -1); res2 = arf_is_int(y); if (!arf_is_int(x) || arf_is_int(y)) { flint_printf("FAIL! (3)\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("res1 = %d, res2 = %d\n\n", res1, res2); abort(); } } arf_clear(x); arf_clear(y); fmpz_clear(t); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_round_uiui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++) { arf_t x, y; slong prec, fix1, fix2; int ret1, ret2, sgnbit; mp_limb_t t[2]; arf_rnd_t rnd; prec = 2 + n_randint(state, 1000); arf_init(x); arf_init(y); arf_randtest_special(x, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); arf_randtest_special(y, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); do { t[0] = n_randtest(state); t[1] = n_randtest(state); } while (t[0] == 0 && t[1] == 0); sgnbit = n_randint(state, 2); switch (n_randint(state, 10)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } if (t[1] != 0) { ret1 = _arf_set_round_mpn(x, &fix1, t, 2, sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(x), 2 * FLINT_BITS + fix1); } else { ret1 = _arf_set_round_mpn(x, &fix1, t, 1, sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(x), FLINT_BITS + fix1); } ret2 = _arf_set_round_uiui(y, &fix2, t[1], t[0], sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(y), 2 * FLINT_BITS + fix2); if (!arf_equal(x, y) || (ret1 != ret2)) { flint_printf("FAIL\n\n"); flint_printf("prec = %wd", prec); flint_printf("\n\n"); flint_printf("hi = %wu, lo = %wu\n\n", t[1], t[0]); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); abort(); } arf_clear(x); arf_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("log_arf...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 5000 * arb_test_multiplier(); iter++) { arf_t x; arb_t y1, y2; slong prec1, prec2, acc1, acc2; prec1 = 2 + n_randint(state, 9000); prec2 = 2 + n_randint(state, 9000); arf_init(x); arb_init(y1); arb_init(y2); arf_randtest_special(x, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y1, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y2, state, 1 + n_randint(state, 9000), 200); if (n_randint(state, 2)) arf_add_ui(x, x, 1, 2 + n_randint(state, 9000), ARF_RND_DOWN); arb_log_arf(y1, x, prec1); arb_log_arf(y2, x, prec2); if (!arb_overlaps(y1, y2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("prec1 = %wd, prec2 = %wd\n\n", prec1, prec2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y1 = "); arb_print(y1); flint_printf("\n\n"); flint_printf("y2 = "); arb_print(y2); flint_printf("\n\n"); abort(); } acc1 = arb_rel_accuracy_bits(y1); acc2 = arb_rel_accuracy_bits(y2); if (arf_sgn(x) > 0) { if (acc1 < prec1 - 2 || acc2 < prec2 - 2) { flint_printf("FAIL: accuracy\n\n"); flint_printf("prec1 = %wd, prec2 = %wd\n\n", prec1, prec2); flint_printf("acc1 = %wd, acc2 = %wd\n\n", acc1, acc2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y1 = "); arb_print(y1); flint_printf("\n\n"); flint_printf("y2 = "); arb_print(y2); flint_printf("\n\n"); abort(); } } arf_clear(x); arb_clear(y1); arb_clear(y2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
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; }
int main() { slong iter; flint_rand_t state; flint_printf("set_round...."); fflush(stdout); flint_randinit(state); { arf_t x, y, z; arf_init(x); arf_init(y); arf_init(z); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits1, bits2; int ret1, ret2; mpfr_t g1, g2; fmpz_t e; arf_rnd_t rnd; bits1 = 1 + n_randint(state, 1000); bits2 = 2 + n_randint(state, 1000); if (n_randint(state, 100) == 0) bits2 = ARF_PREC_EXACT; switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } fmpz_init(e); mpfr_init2(g1, FLINT_MAX(2, bits1)); mpfr_init2(g2, FLINT_MIN(bits2, 10000)); if (n_randint(state, 100) == 0) { arf_clear(x); arf_clear(y); arf_clear(z); arf_init(x); arf_init(y); arf_init(z); } /* dirty output variables */ if (n_randint(state, 2)) { arf_randtest_special(y, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); arf_randtest_special(z, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); } arf_randtest_special(x, state, bits1, 1 + n_randint(state, 10)); arf_get_mpfr(g1, x, MPFR_RNDD); /* exact */ /* test large exponents */ if (n_randint(state, 4) == 0) fmpz_randtest(e, state, 1 + n_randint(state, 100)); if (!arf_is_special(x)) fmpz_add(ARF_EXPREF(x), ARF_EXPREF(x), e); ret1 = arf_set_round(y, x, bits2, rnd); ret2 = mpfr_set(g2, g1, arf_rnd_to_mpfr(rnd)); arf_set_mpfr(z, g2); if (!arf_is_special(y)) fmpz_sub(ARF_EXPREF(y), ARF_EXPREF(y), e); if (!arf_equal(y, z) || ((ret1 == ARF_RESULT_EXACT) != (ret2 == 0))) { flint_printf("FAIL\n\n"); flint_printf("bits1: %wd\n", bits1); flint_printf("bits2: %wd\n", bits2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); flint_abort(); } if (!arf_is_special(x)) fmpz_add(ARF_EXPREF(x), ARF_EXPREF(x), e); ret1 = arf_set_round(y, x, bits2, rnd); arf_set(z, x); ret2 = arf_set_round(z, z, bits2, rnd); if (!arf_equal(y, z) || ret1 != ret2) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("bits1: %wd\n", bits1); flint_printf("bits2: %wd\n", bits2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); flint_abort(); } mpfr_clear(g1); mpfr_clear(g2); fmpz_clear(e); } arf_clear(x); arf_clear(y); arf_clear(z); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
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; }
int main() { long iter, iter2; flint_rand_t state; printf("add_fmpz...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { arf_t x, z, v; fmpz_t y; long prec, r1, r2; arf_rnd_t rnd; arf_init(x); arf_init(z); arf_init(v); fmpz_init(y); for (iter2 = 0; iter2 < 100; iter2++) { arf_randtest_special(x, state, 2000, 10); fmpz_randtest(y, state, 2000); prec = 2 + n_randint(state, 2000); if (n_randint(state, 10) == 0 && fmpz_bits(ARF_EXPREF(x)) < 10) { prec = ARF_PREC_EXACT; } 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; } switch (n_randint(state, 2)) { case 0: r1 = arf_add_fmpz(z, x, y, prec, rnd); r2 = arf_add_fmpz_naive(v, x, y, prec, rnd); if (!arf_equal(z, v) || r1 != r2) { printf("FAIL!\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("x = "); arf_print(x); printf("\n\n"); printf("y = "); fmpz_print(y); printf("\n\n"); printf("z = "); arf_print(z); printf("\n\n"); printf("v = "); arf_print(v); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; default: r2 = arf_add_fmpz_naive(v, x, y, prec, rnd); r1 = arf_add_fmpz(x, x, y, prec, rnd); if (!arf_equal(x, v) || r1 != r2) { printf("FAIL (aliasing)!\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("x = "); arf_print(x); printf("\n\n"); printf("y = "); fmpz_print(y); printf("\n\n"); printf("v = "); arf_print(v); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; } } arf_clear(x); arf_clear(z); arf_clear(v); fmpz_clear(y); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter; flint_rand_t state; printf("atan_arf...."); fflush(stdout); flint_randinit(state); /* self-consistency test */ for (iter = 0; iter < 5000; iter++) { arf_t x; arb_t y1, y2; long prec1, prec2, acc1, acc2; prec1 = 2 + n_randint(state, 9000); prec2 = 2 + n_randint(state, 9000); arf_init(x); arb_init(y1); arb_init(y2); arf_randtest_special(x, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y1, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y2, state, 1 + n_randint(state, 9000), 200); if (n_randint(state, 2)) arf_add_ui(x, x, 1, 2 + n_randint(state, 9000), ARF_RND_DOWN); arb_atan_arf(y1, x, prec1); arb_atan_arf(y2, x, prec2); if (!arb_overlaps(y1, y2)) { printf("FAIL: overlap\n\n"); printf("prec1 = %ld, prec2 = %ld\n\n", prec1, prec2); printf("x = "); arf_print(x); printf("\n\n"); printf("y1 = "); arb_print(y1); printf("\n\n"); printf("y2 = "); arb_print(y2); printf("\n\n"); abort(); } acc1 = arb_rel_accuracy_bits(y1); acc2 = arb_rel_accuracy_bits(y2); if (!arf_is_nan(x)) { if (acc1 < prec1 - 2 || acc2 < prec2 - 2) { printf("FAIL: accuracy\n\n"); printf("prec1 = %ld, prec2 = %ld\n\n", prec1, prec2); printf("acc1 = %ld, acc2 = %ld\n\n", acc1, acc2); printf("x = "); arf_printd(x, 50); printf("\n\n"); printf("y1 = "); arb_printd(y1, 50); printf("\n\n"); printf("y2 = "); arb_printd(y2, 50); printf("\n\n"); abort(); } } arf_clear(x); arb_clear(y1); arb_clear(y2); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter; flint_rand_t state; printf("add_error...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t m, r; arb_init(a); arb_init(b); arb_init(c); arf_init(m); arf_init(r); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 10); arf_randtest_special(m, state, 1 + n_randint(state, 2000), 10); arf_randtest_special(r, state, 1 + n_randint(state, 2000), 10); /* c = a plus error bounds */ arb_set(c, a); arf_set(arb_midref(b), m); arf_get_mag(arb_radref(b), r); arb_add_error(c, b); /* b = a + random point */ arb_set(b, a); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), m, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), m, ARF_PREC_EXACT, ARF_RND_DOWN); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), r, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), r, ARF_PREC_EXACT, ARF_RND_DOWN); /* should this be done differently? */ if (arf_is_nan(arb_midref(b))) arf_zero(arb_midref(b)); if (!arb_contains(c, b)) { printf("FAIL (arb_add_error)\n\n"); printf("a = "); arb_printn(a, 50, 0); printf("\n\n"); printf("b = "); arb_printn(b, 50, 0); printf("\n\n"); printf("c = "); arb_printn(c, 50, 0); printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arf_clear(m); arf_clear(r); } for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t m; arb_init(a); arb_init(b); arb_init(c); arf_init(m); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 10); arf_randtest_special(m, state, 1 + n_randint(state, 2000), 10); /* c = a plus error bounds */ arb_set(c, a); arb_add_error_arf(c, m); /* b = a + random point */ arb_set(b, a); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), m, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), m, ARF_PREC_EXACT, ARF_RND_DOWN); /* should this be done differently? */ if (arf_is_nan(arb_midref(b))) arf_zero(arb_midref(b)); if (!arb_contains(c, b)) { printf("FAIL (arb_add_error_arf)\n\n"); printf("a = "); arb_printn(a, 50, 0); printf("\n\n"); printf("b = "); arb_printn(b, 50, 0); printf("\n\n"); printf("c = "); arb_printn(c, 50, 0); printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arf_clear(m); } for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t t; mag_t r; arb_init(a); arb_init(b); arb_init(c); mag_init(r); arf_init(t); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 10); mag_randtest(r, state, 10); /* c = a plus error bounds */ arb_set(c, a); arb_add_error_mag(c, r); /* b = a + random point */ arb_set(b, a); arf_set_mag(t, r); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); /* should this be done differently? */ if (arf_is_nan(arb_midref(b))) arf_zero(arb_midref(b)); if (!arb_contains(c, b)) { printf("FAIL (arb_add_error_mag)\n\n"); printf("a = "); arb_printn(a, 50, 0); printf("\n\n"); printf("b = "); arb_printn(b, 50, 0); printf("\n\n"); printf("c = "); arb_printn(c, 50, 0); printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); mag_clear(r); arf_clear(t); } for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t t; long e; arb_init(a); arb_init(b); arb_init(c); arf_init(t); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 10); e = n_randint(state, 10) - 10; /* c = a plus error bounds */ arb_set(c, a); arb_add_error_2exp_si(c, e); /* b = a + random point */ arb_set(b, a); arf_one(t); arf_mul_2exp_si(t, t, e); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); /* should this be done differently? */ if (arf_is_nan(arb_midref(b))) arf_zero(arb_midref(b)); if (!arb_contains(c, b)) { printf("FAIL (arb_add_error_2exp_si)\n\n"); printf("a = "); arb_printn(a, 50, 0); printf("\n\n"); printf("b = "); arb_printn(b, 50, 0); printf("\n\n"); printf("c = "); arb_printn(c, 50, 0); printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arf_clear(t); } for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t t; fmpz_t e; arb_init(a); arb_init(b); arb_init(c); arf_init(t); fmpz_init(e); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 10); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 10); fmpz_randtest(e, state, 10); /* c = a plus error bounds */ arb_set(c, a); arb_add_error_2exp_fmpz(c, e); /* b = a + random point */ arb_set(b, a); arf_one(t); arf_mul_2exp_fmpz(t, t, e); if (n_randint(state, 2)) arf_add(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); else arf_sub(arb_midref(b), arb_midref(b), t, ARF_PREC_EXACT, ARF_RND_DOWN); /* should this be done differently? */ if (arf_is_nan(arb_midref(b))) arf_zero(arb_midref(b)); if (!arb_contains(c, b)) { printf("FAIL (arb_add_error_2exp_fmpz)\n\n"); printf("a = "); arb_printn(a, 50, 0); printf("\n\n"); printf("b = "); arb_printn(b, 50, 0); printf("\n\n"); printf("c = "); arb_printn(c, 50, 0); printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arf_clear(t); fmpz_clear(e); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("div_arf...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { arb_t a, b, c, d; arf_t x; slong prec; arb_init(a); arb_init(b); arb_init(c); arb_init(d); arf_init(x); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); arf_randtest_special(x, state, 1 + n_randint(state, 2000), 100); prec = 2 + n_randint(state, 2000); arb_set_arf(b, x); arb_div_arf(c, a, x, prec); arb_div(d, a, b, prec); if (!arb_equal(c, d)) { flint_printf("FAIL\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); flint_printf("d = "); arb_print(d); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arb_clear(d); arf_clear(x); } /* aliasing */ for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; arf_t x; slong prec; arb_init(a); arb_init(b); arb_init(c); arf_init(x); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); arf_randtest_special(x, state, 1 + n_randint(state, 2000), 100); prec = 2 + n_randint(state, 2000); arb_set_arf(b, x); arb_div_arf(c, a, x, prec); arb_div_arf(a, a, x, prec); if (!arb_equal(a, c)) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arf_clear(x); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter, iter2; flint_rand_t state; flint_printf("add...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arf_t x, y, z, v; slong prec, r1, r2; arf_rnd_t rnd; fmpz_t t; arf_init(x); arf_init(y); arf_init(z); arf_init(v); fmpz_init(t); for (iter2 = 0; iter2 < 100; iter2++) { arf_randtest_special(x, state, 2000, 100); arf_randtest_special(y, state, 2000, 100); prec = 2 + n_randint(state, 2000); switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } rnd = ARF_RND_DOWN; if (arf_is_normal(x) && arf_is_normal(y)) { fmpz_sub(t, ARF_EXPREF(x), ARF_EXPREF(y)); /* if not too far apart, sometimes test exact addition */ if (fmpz_bits(t) < 10) { if (n_randint(state, 10) == 0) prec = ARF_PREC_EXACT; } else if (rnd == ARF_RND_NEAR) { /* large shift not supported in add_naive */ rnd = ARF_RND_DOWN; } } switch (n_randint(state, 5)) { case 0: r1 = arf_add(z, x, y, prec, rnd); r2 = arf_add_naive(v, x, y, prec, rnd); if (!arf_equal(z, v) || r1 != r2) { flint_printf("FAIL!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; case 1: r1 = arf_add(z, x, x, prec, rnd); r2 = arf_add_naive(v, x, x, prec, rnd); if (!arf_equal(z, v) || r1 != r2) { flint_printf("FAIL (aliasing 1)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; case 2: r2 = arf_add_naive(v, x, x, prec, rnd); r1 = arf_add(x, x, x, prec, rnd); if (!arf_equal(v, x) || r1 != r2) { flint_printf("FAIL (aliasing 2)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; case 3: r2 = arf_add_naive(v, x, y, prec, rnd); r1 = arf_add(x, x, y, prec, rnd); if (!arf_equal(x, v) || r1 != r2) { flint_printf("FAIL (aliasing 3)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; default: r2 = arf_add_naive(v, x, y, prec, rnd); r1 = arf_add(x, y, x, prec, rnd); if (!arf_equal(x, v) || r1 != r2) { flint_printf("FAIL (aliasing 4)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; } } arf_clear(x); arf_clear(y); arf_clear(z); arf_clear(v); fmpz_clear(t); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("get_d...."); fflush(stdout); flint_randinit(state); /* test exact roundtrip */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arf_t x, z; double y; arf_rnd_t rnd; arf_init(x); arf_init(z); 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; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } arf_randtest_special(x, state, 53, 8); y = arf_get_d(x, rnd); arf_set_d(z, y); if (!arf_equal(x, z)) { flint_printf("FAIL:\n\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = %.17g\n\n", y); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); abort(); } arf_clear(x); arf_clear(z); } /* test rounding */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arf_t x, z, w; arf_rnd_t rnd; double y; arf_init(x); arf_init(z); arf_init(w); arf_randtest_special(x, state, 300, 8); 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; } y = arf_get_d(x, rnd); arf_set_d(w, y); arf_set_round(z, x, 53, rnd); if (!arf_equal(w, z)) { flint_printf("FAIL:\n\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = %.17g\n\n", y); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("w = "); arf_print(w); flint_printf("\n\n"); abort(); } arf_clear(x); arf_clear(z); arf_clear(w); } /* compare with mpfr */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arf_t x, r1, r2; arf_rnd_t rnd; mpfr_t t; double d1, d2; arf_init(x); arf_init(r1); arf_init(r2); mpfr_init2(t, 300); arf_randtest_special(x, state, 300, 20); arf_get_mpfr(t, x, MPFR_RNDD); 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; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } d1 = arf_get_d(x, rnd); d2 = mpfr_get_d(t, rnd_to_mpfr(rnd)); arf_set_d(r1, d1); arf_set_d(r2, d2); if (!arf_equal(r1, r2)) { flint_printf("FAIL:\n\n"); flint_printf("rnd = %i\n\n", rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("d1 = %.17g\n\n", d1); flint_printf("d2 = %.17g\n\n", d2); flint_printf("r1 = "); arf_print(r1); flint_printf("\n\n"); flint_printf("r2 = "); arf_print(r2); flint_printf("\n\n"); abort(); } arf_clear(x); arf_clear(r1); arf_clear(r2); mpfr_clear(t); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter, iter2; flint_rand_t state; printf("complex_mul...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { arf_t e1, f1, e2, f2, a, b, c, d; long prec, r1, r2; arf_rnd_t rnd; arf_init(a); arf_init(b); arf_init(c); arf_init(d); arf_init(e1); arf_init(f1); arf_init(e2); arf_init(f2); for (iter2 = 0; iter2 < 100; iter2++) { arf_randtest_special(a, state, 3000, 100); arf_randtest_special(b, state, 3000, 100); arf_randtest_special(c, state, 3000, 100); arf_randtest_special(d, state, 3000, 100); prec = 2 + n_randint(state, 3000); 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; } switch (n_randint(state, 5)) { case 0: r1 = arf_complex_mul(e1, f1, a, b, c, d, prec, rnd); r2 = arf_complex_mul_fallback(e2, f2, a, b, c, d, prec, rnd); if (!arf_equal(e1, e2) || !arf_equal(f1, f2) || r1 != r2) { printf("FAIL!\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("a = "); arf_print(a); printf("\n\n"); printf("b = "); arf_print(b); printf("\n\n"); printf("c = "); arf_print(c); printf("\n\n"); printf("d = "); arf_print(d); printf("\n\n"); printf("e1 = "); arf_print(e1); printf("\n\n"); printf("f1 = "); arf_print(f1); printf("\n\n"); printf("e2 = "); arf_print(e2); printf("\n\n"); printf("f2 = "); arf_print(f2); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; case 1: arf_set(c, a); arf_set(d, b); r1 = arf_complex_mul(e1, f1, a, b, a, b, prec, rnd); r2 = arf_complex_mul_fallback(e2, f2, a, b, c, d, prec, rnd); if (!arf_equal(e1, e2) || !arf_equal(f1, f2) || r1 != r2) { printf("FAIL! (aliasing 1)\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("a = "); arf_print(a); printf("\n\n"); printf("b = "); arf_print(b); printf("\n\n"); printf("c = "); arf_print(c); printf("\n\n"); printf("d = "); arf_print(d); printf("\n\n"); printf("e1 = "); arf_print(e1); printf("\n\n"); printf("f1 = "); arf_print(f1); printf("\n\n"); printf("e2 = "); arf_print(e2); printf("\n\n"); printf("f2 = "); arf_print(f2); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; case 2: r1 = arf_complex_mul_fallback(e1, f1, a, b, a, b, prec, rnd); r2 = arf_complex_mul(a, b, a, b, a, b, prec, rnd); if (!arf_equal(e1, a) || !arf_equal(f1, b) || r1 != r2) { printf("FAIL! (aliasing 2)\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("a = "); arf_print(a); printf("\n\n"); printf("b = "); arf_print(b); printf("\n\n"); printf("e1 = "); arf_print(e1); printf("\n\n"); printf("f1 = "); arf_print(f1); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; case 3: r1 = arf_complex_mul_fallback(e1, f1, a, b, c, d, prec, rnd); r2 = arf_complex_mul(a, b, a, b, c, d, prec, rnd); if (!arf_equal(e1, a) || !arf_equal(f1, b) || r1 != r2) { printf("FAIL! (aliasing 3)\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("a = "); arf_print(a); printf("\n\n"); printf("b = "); arf_print(b); printf("\n\n"); printf("c = "); arf_print(c); printf("\n\n"); printf("d = "); arf_print(d); printf("\n\n"); printf("e1 = "); arf_print(e1); printf("\n\n"); printf("f1 = "); arf_print(f1); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; default: r1 = arf_complex_mul_fallback(e1, f1, a, b, c, d, prec, rnd); r2 = arf_complex_mul(c, d, a, b, c, d, prec, rnd); if (!arf_equal(e1, c) || !arf_equal(f1, d) || r1 != r2) { printf("FAIL! (aliasing 4)\n"); printf("prec = %ld, rnd = %d\n\n", prec, rnd); printf("a = "); arf_print(a); printf("\n\n"); printf("b = "); arf_print(b); printf("\n\n"); printf("c = "); arf_print(c); printf("\n\n"); printf("d = "); arf_print(d); printf("\n\n"); printf("e1 = "); arf_print(e1); printf("\n\n"); printf("f1 = "); arf_print(f1); printf("\n\n"); printf("r1 = %ld, r2 = %ld\n", r1, r2); abort(); } break; } } arf_clear(a); arf_clear(b); arf_clear(c); arf_clear(d); arf_clear(e1); arf_clear(f1); arf_clear(e2); arf_clear(f2); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter, iter2; flint_rand_t state; flint_printf("addmul_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { arf_t x, z, v; slong y; slong prec, r1, r2; arf_rnd_t rnd; arf_init(x); arf_init(z); arf_init(v); for (iter2 = 0; iter2 < 100; iter2++) { arf_randtest_special(x, state, 2000, 100); y = z_randtest(state); arf_randtest_special(z, state, 2000, 100); arf_set(v, z); prec = 2 + n_randint(state, 2000); if (n_randint(state, 10) == 0 && fmpz_bits(ARF_EXPREF(x)) < 10 && fmpz_bits(ARF_EXPREF(z)) < 10) { prec = ARF_PREC_EXACT; } switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } switch (n_randint(state, 2)) { case 0: r1 = arf_addmul_si(z, x, y, prec, rnd); r2 = arf_addmul_si_naive(v, x, y, prec, rnd); if (!arf_equal(z, v) || r1 != r2) { flint_printf("FAIL!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = %wd", y); flint_printf("\n\n"); flint_printf("z = "); arf_debug(z); flint_printf("\n\n"); flint_printf("v = "); arf_debug(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; default: r2 = arf_addmul_si_naive(v, v, y, prec, rnd); r1 = arf_addmul_si(z, z, y, prec, rnd); if (!arf_equal(v, z) || r1 != r2) { flint_printf("FAIL (aliasing)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("y = %wd", y); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; } } arf_clear(x); arf_clear(z); arf_clear(v); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_round_mpz...."); fflush(stdout); flint_randinit(state); { arf_t x, y; arf_init(x); arf_init(y); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits1, bits2; int ret1, ret2; fmpz_t a; mpz_t b; mpfr_t g; arf_rnd_t rnd; bits1 = 1 + n_randint(state, 1000); bits2 = 2 + n_randint(state, 1000); if (n_randint(state, 100) == 0) bits2 = ARF_PREC_EXACT; fmpz_init(a); mpz_init(b); mpfr_init2(g, FLINT_MIN(bits2, 10000)); if (n_randint(state, 100) == 0) { arf_clear(x); arf_clear(y); arf_init(x); arf_init(y); } /* dirty output variables */ if (n_randint(state, 2)) { arf_randtest_special(x, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); arf_randtest_special(y, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); } fmpz_randtest(a, state, bits1); fmpz_get_mpz(b, a); switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } ret1 = arf_set_round_mpz(x, b, bits2, rnd); ret2 = mpfr_set_z(g, b, arf_rnd_to_mpfr(rnd)); arf_set_mpfr(y, g); arf_equal(x, y); if (!arf_equal(x, y) || ((ret1 == ARF_RESULT_EXACT) != (ret2 == 0))) { flint_printf("FAIL\n\n"); flint_printf("bits1: %wd\n", bits1); flint_printf("bits2: %wd\n", bits2); flint_printf("a = "); fmpz_print(a); flint_printf("\n\n"); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); abort(); } fmpz_clear(a); mpz_clear(b); mpfr_clear(g); } arf_clear(x); arf_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }