From c50370d897db158e87ed1f4d927299abcf49a558 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Mon, 10 Sep 2012 23:50:33 +0200 Subject: [PATCH] add test code for ball arithmetic --- fmprb/div.c | 9 ++- fmprb/pow.c | 8 +- fmprb/test/t-add.c | 168 ++++++++++++++++++++++++++++++++++++++++ fmprb/test/t-addmul.c | 171 +++++++++++++++++++++++++++++++++++++++++ fmprb/test/t-div.c | 174 ++++++++++++++++++++++++++++++++++++++++++ fmprb/test/t-mul.c | 168 ++++++++++++++++++++++++++++++++++++++++ fmprb/test/t-sub.c | 168 ++++++++++++++++++++++++++++++++++++++++ fmprb/test/t-submul.c | 171 +++++++++++++++++++++++++++++++++++++++++ fmprb/zeta_ui.c | 4 +- 9 files changed, 1034 insertions(+), 7 deletions(-) create mode 100644 fmprb/test/t-add.c create mode 100644 fmprb/test/t-addmul.c create mode 100644 fmprb/test/t-div.c create mode 100644 fmprb/test/t-mul.c create mode 100644 fmprb/test/t-sub.c create mode 100644 fmprb/test/t-submul.c diff --git a/fmprb/div.c b/fmprb/div.c index 8f752aac..1085b93e 100644 --- a/fmprb/div.c +++ b/fmprb/div.c @@ -30,6 +30,13 @@ fmprb_div(fmprb_t z, const fmprb_t x, const fmprb_t y, long prec) { long r; + if (fmprb_contains_zero(y)) + { + fmpr_zero(fmprb_midref(z)); + fmpr_pos_inf(fmprb_radref(z)); + return; + } + if (fmprb_is_exact(y)) { if (fmprb_is_exact(x)) @@ -52,7 +59,7 @@ fmprb_div(fmprb_t z, const fmprb_t x, const fmprb_t y, long prec) else { /* x/y - (x+a)/(y-b) = a/(b-y) + x*b/(y*(b-y)) */ - /* XXX: require y > b! */ + /* where we assume y > b */ fmpr_t t, u, by; diff --git a/fmprb/pow.c b/fmprb/pow.c index 77276daa..6dfbd836 100644 --- a/fmprb/pow.c +++ b/fmprb/pow.c @@ -30,7 +30,7 @@ void fmprb_pow_ui(fmprb_t y, const fmprb_t b, ulong e, long prec) { - long i; + long i, wp; if (y == b) { @@ -50,11 +50,13 @@ fmprb_pow_ui(fmprb_t y, const fmprb_t b, ulong e, long prec) fmprb_set(y, b); + wp = FMPR_PREC_ADD(prec, FLINT_BIT_COUNT(e)); + for (i = FLINT_BIT_COUNT(e) - 2; i >= 0; i--) { - fmprb_mul(y, y, y, prec); + fmprb_mul(y, y, y, wp); if (e & (1UL<