void arf_set_fmpr(arf_t y, const fmpr_t x) { if (fmpr_is_special(x)) { if (fmpr_is_zero(x)) arf_zero(y); else if (fmpr_is_pos_inf(x)) arf_pos_inf(y); else if (fmpr_is_neg_inf(x)) arf_neg_inf(y); else arf_nan(y); } else { arf_set_fmpz(y, fmpr_manref(x)); fmpz_add_inline(ARF_EXPREF(y), ARF_EXPREF(y), fmpr_expref(x)); } }
static __inline__ void _arb_poly_addmullow_rad(arb_ptr z, fmpz * zz, const fmpz * xz, const double * xdbl, const fmpz * xexps, const slong * xblocks, slong xlen, const fmpz * yz, const double * ydbl, const fmpz * yexps, const slong * yblocks, slong ylen, slong n) { slong i, j, k, ii, xp, yp, xl, yl, bn; fmpz_t zexp; mag_t t; fmpz_init(zexp); mag_init(t); for (i = 0; (xp = xblocks[i]) != xlen; i++) { for (j = 0; (yp = yblocks[j]) != ylen; j++) { if (xp + yp >= n) continue; xl = xblocks[i + 1] - xp; yl = yblocks[j + 1] - yp; bn = FLINT_MIN(xl + yl - 1, n - xp - yp); xl = FLINT_MIN(xl, bn); yl = FLINT_MIN(yl, bn); fmpz_add_inline(zexp, xexps + i, yexps + j); if (xl > 1 && yl > 1 && (xl < DOUBLE_BLOCK_MAX_LENGTH || yl < DOUBLE_BLOCK_MAX_LENGTH)) { fmpz_add_ui(zexp, zexp, 2 * DOUBLE_BLOCK_SHIFT); for (k = 0; k < bn; k++) { /* Classical multiplication (may round down!) */ double ss = 0.0; for (ii = FLINT_MAX(0, k - yl + 1); ii <= FLINT_MIN(xl - 1, k); ii++) { ss += xdbl[xp + ii] * ydbl[yp + k - ii]; } /* Compensate for rounding error */ ss *= DOUBLE_ROUNDING_FACTOR; mag_set_d_2exp_fmpz(t, ss, zexp); mag_add(arb_radref(z + xp + yp + k), arb_radref(z + xp + yp + k), t); } } else { if (xl >= yl) _fmpz_poly_mullow(zz, xz + xp, xl, yz + yp, yl, bn); else _fmpz_poly_mullow(zz, yz + yp, yl, xz + xp, xl, bn); for (k = 0; k < bn; k++) { mag_set_fmpz_2exp_fmpz(t, zz + k, zexp); mag_add(arb_radref(z + xp + yp + k), arb_radref(z + xp + yp + k), t); } } } } fmpz_clear(zexp); mag_clear(t); }
int main() { slong iter; flint_rand_t state; flint_printf("add_inline...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { fmpz_t a, b, c, d; fmpz_init(a); fmpz_init(b); fmpz_init(c); fmpz_init(d); fmpz_randtest(a, state, 1 + n_randint(state, 200)); fmpz_randtest(b, state, 1 + n_randint(state, 200)); fmpz_randtest(c, state, 1 + n_randint(state, 200)); fmpz_randtest(d, state, 1 + n_randint(state, 200)); fmpz_add(c, a, b); fmpz_add_inline(d, a, b); if (!fmpz_equal(c, d)) { flint_printf("FAIL\n"); fmpz_print(a); flint_printf("\n\n"); fmpz_print(b); flint_printf("\n\n"); fmpz_print(c); flint_printf("\n\n"); fmpz_print(d); flint_printf("\n\n"); abort(); } fmpz_add_inline(a, a, b); if (!fmpz_equal(c, a)) { flint_printf("FAIL (aliasing 1)\n"); fmpz_print(a); flint_printf("\n\n"); fmpz_print(b); flint_printf("\n\n"); fmpz_print(c); flint_printf("\n\n"); fmpz_print(d); flint_printf("\n\n"); abort(); } fmpz_randtest(a, state, 1 + n_randint(state, 200)); fmpz_add(c, a, b); fmpz_add_inline(b, a, b); if (!fmpz_equal(c, b)) { flint_printf("FAIL (aliasing 2)\n"); fmpz_print(a); flint_printf("\n\n"); fmpz_print(b); flint_printf("\n\n"); fmpz_print(c); flint_printf("\n\n"); fmpz_print(d); flint_printf("\n\n"); abort(); } fmpz_add(d, a, a); fmpz_add_inline(c, a, a); if (!fmpz_equal(c, d)) { flint_printf("FAIL (aliasing 3)\n"); fmpz_print(a); flint_printf("\n\n"); fmpz_print(b); flint_printf("\n\n"); fmpz_print(c); flint_printf("\n\n"); fmpz_print(d); flint_printf("\n\n"); abort(); } fmpz_add(d, a, a); fmpz_add_inline(a, a, a); if (!fmpz_equal(d, a)) { flint_printf("FAIL (aliasing 4)\n"); fmpz_print(a); flint_printf("\n\n"); fmpz_print(b); flint_printf("\n\n"); fmpz_print(c); flint_printf("\n\n"); fmpz_print(d); flint_printf("\n\n"); abort(); } fmpz_clear(a); fmpz_clear(b); fmpz_clear(c); fmpz_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }