void arf_fprint(FILE * file, const arf_t x) { if (arf_is_normal(x)) { fmpz_t man, exp; fmpz_init(man); fmpz_init(exp); arf_get_fmpz_2exp(man, exp, x); flint_fprintf(file, "("); fmpz_fprint(file, man); flint_fprintf(file, " * 2^"); fmpz_fprint(file, exp); flint_fprintf(file, ")"); fmpz_clear(man); fmpz_clear(exp); } else { if (arf_is_zero(x)) flint_fprintf(file, "(0)"); else if (arf_is_pos_inf(x)) flint_fprintf(file, "(+inf)"); else if (arf_is_neg_inf(x)) flint_fprintf(file, "(-inf)"); else flint_fprintf(file, "(nan)"); } }
void fprintarf(FILE *fp,const arf_t x) { static int init; static fmpz_t m,e; if (!init) { fmpz_init(m); fmpz_init(e); init = 1; } arf_get_fmpz_2exp(m,e,x); fmpz_fprint(fp,m); fprintf(fp," "); fmpz_fprint(fp,e); }
void arf_get_fmpr(fmpr_t y, const arf_t x) { if (arf_is_special(x)) { if (arf_is_zero(x)) fmpr_zero(y); else if (arf_is_pos_inf(x)) fmpr_pos_inf(y); else if (arf_is_neg_inf(x)) fmpr_neg_inf(y); else fmpr_nan(y); } else { arf_get_fmpz_2exp(fmpr_manref(y), fmpr_expref(y), x); } }
void arf_get_fmpq(fmpq_t y, const arf_t x) { if (arf_is_zero(x)) { fmpq_zero(y); } else if (arf_is_special(x) || !ARF_IS_LAGOM(x)) { flint_printf("exception: arf_get_fmpq: cannot convert to rational\n"); abort(); } else { fmpz_t man, exp; slong e; fmpz_init(man); fmpz_init(exp); arf_get_fmpz_2exp(man, exp, x); e = *exp; fmpz_set_ui(fmpq_denref(y), UWORD(1)); if (e >= 0) { fmpz_mul_2exp(fmpq_numref(y), man, e); } else { fmpz_set(fmpq_numref(y), man); fmpz_mul_2exp(fmpq_denref(y), fmpq_denref(y), -e); } fmpz_clear(man); fmpz_clear(exp); } }
static __inline__ void _arb_vec_get_fmpz_2exp_blocks(fmpz * coeffs, fmpz * exps, slong * blocks, const fmpz_t scale, arb_srcptr x, slong len, slong prec) { fmpz_t top, bot, t, b, v, block_top, block_bot; slong i, j, s, block, bits, maxheight; int in_zero; fmpz_init(top); fmpz_init(bot); fmpz_init(t); fmpz_init(b); fmpz_init(v); fmpz_init(block_top); fmpz_init(block_bot); blocks[0] = 0; block = 0; in_zero = 1; if (prec == ARF_PREC_EXACT) maxheight = ARF_PREC_EXACT; else maxheight = ALPHA * prec + BETA; for (i = 0; i < len; i++) { bits = arf_bits(arb_midref(x + i)); /* Skip (must be zero, since we assume there are no Infs/NaNs). */ if (bits == 0) continue; /* Bottom and top exponent of current number */ fmpz_set(top, ARF_EXPREF(arb_midref(x + i))); fmpz_submul_ui(top, scale, i); fmpz_sub_ui(bot, top, bits); /* Extend current block. */ if (in_zero) { fmpz_swap(block_top, top); fmpz_swap(block_bot, bot); } else { fmpz_max(t, top, block_top); fmpz_min(b, bot, block_bot); fmpz_sub(v, t, b); /* extend current block */ if (fmpz_cmp_ui(v, maxheight) < 0) { fmpz_swap(block_top, t); fmpz_swap(block_bot, b); } else /* start new block */ { /* write exponent for previous block */ fmpz_set(exps + block, block_bot); block++; blocks[block] = i; fmpz_swap(block_top, top); fmpz_swap(block_bot, bot); } } in_zero = 0; } /* write exponent for last block */ fmpz_set(exps + block, block_bot); /* end marker */ blocks[block + 1] = len; /* write the block data */ for (i = 0; blocks[i] != len; i++) { for (j = blocks[i]; j < blocks[i + 1]; j++) { if (arf_is_special(arb_midref(x + j))) { fmpz_zero(coeffs + j); } else { /* TODO: make this a single operation */ arf_get_fmpz_2exp(coeffs + j, bot, arb_midref(x + j)); fmpz_mul_ui(t, scale, j); fmpz_sub(t, bot, t); s = _fmpz_sub_small(t, exps + i); if (s < 0) abort(); /* Bug catcher */ fmpz_mul_2exp(coeffs + j, coeffs + j, s); } } } fmpz_clear(top); fmpz_clear(bot); fmpz_clear(t); fmpz_clear(b); fmpz_clear(v); fmpz_clear(block_top); fmpz_clear(block_bot); }
int main(int argc, char *argv[]) { slong i, len, prec, num_threads; char * out_file; arb_ptr z; if (argc < 2) { flint_printf("keiper_li n [-prec prec] [-threads num_threads] [-out out_file]\n"); return 1; } len = atol(argv[1]) + 1; prec = 1.1 * len + 50; num_threads = 1; out_file = NULL; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-prec")) prec = atol(argv[i+1]); else if (!strcmp(argv[i], "-threads")) num_threads = atol(argv[i+1]); else if (!strcmp(argv[i], "-out")) out_file = argv[i+1]; } flint_set_num_threads(num_threads); z = _arb_vec_init(len); keiper_li_series(z, len, prec); for (i = 0; i < len; i++) { if (i <= 10 || len - i <= 10) { flint_printf("%wd: ", i); arb_printd(z + i, 50); flint_printf("\n"); } } SHOW_MEMORY_USAGE if (out_file != NULL) { fmpz_t man, exp; arf_t t; FILE * fp = fopen(out_file, "w"); fmpz_init(man); fmpz_init(exp); arf_init(t); for (i = 0; i < len; i++) { arf_get_fmpz_2exp(man, exp, arb_midref(z + i)); flint_fprintf(fp, "%wd ", i); fmpz_fprint(fp, man); flint_fprintf(fp, " "); fmpz_fprint(fp, exp); flint_fprintf(fp, " "); arf_set_mag(t, arb_radref(z + i)); arf_get_fmpz_2exp(man, exp, t); fmpz_fprint(fp, man); flint_fprintf(fp, " "); fmpz_fprint(fp, exp); flint_fprintf(fp, "\n"); } fclose(fp); fmpz_clear(man); fmpz_clear(exp); arf_clear(t); } _arb_vec_clear(z, len); flint_cleanup(); return 0; }