From 8f9f343127a50a8fcf0017793b8d78edae8c375e Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Tue, 14 Feb 2017 14:31:48 +0100 Subject: [PATCH] add arb_is_int_2exp_si and acb_is_int_2exp_si --- acb.h | 6 ++++++ acb/polygamma.c | 2 +- acb_elliptic/e_inc.c | 3 +-- acb_elliptic/f.c | 3 +-- acb_elliptic/pi.c | 4 +--- arb.h | 7 +++++++ doc/source/acb.rst | 4 ++++ doc/source/arb.rst | 4 ++++ 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/acb.h b/acb.h index 42136fe9..735dd6eb 100644 --- a/acb.h +++ b/acb.h @@ -110,6 +110,12 @@ acb_is_int(const acb_t z) return arb_is_zero(acb_imagref(z)) && arb_is_int(acb_realref(z)); } +ACB_INLINE int +acb_is_int_2exp_si(const acb_t z, slong e) +{ + return arb_is_zero(acb_imagref(z)) && arb_is_int_2exp_si(acb_realref(z), e); +} + ACB_INLINE void acb_zero(acb_t z) { diff --git a/acb/polygamma.c b/acb/polygamma.c index af601c40..161653de 100644 --- a/acb/polygamma.c +++ b/acb/polygamma.c @@ -30,7 +30,7 @@ acb_polygamma(acb_t res, const acb_t s, const acb_t z, slong prec) acb_gamma(u, t, prec); acb_hurwitz_zeta(t, t, z, prec); - if (arf_is_int_2exp_si(arb_midref(acb_realref(s)), 1)) + if (acb_is_int_2exp_si(s, 1)) acb_neg(t, t); acb_mul(res, t, u, prec); diff --git a/acb_elliptic/e_inc.c b/acb_elliptic/e_inc.c index ffb87b89..d01deda1 100644 --- a/acb_elliptic/e_inc.c +++ b/acb_elliptic/e_inc.c @@ -92,8 +92,7 @@ acb_elliptic_e_inc(acb_t res, const acb_t phi, const acb_t m, int times_pi, slon return; } - if (times_pi && acb_is_real(phi) && arb_is_exact(acb_realref(phi)) && - arf_is_int_2exp_si(arb_midref(acb_realref(phi)), -1)) + if (times_pi && acb_is_int_2exp_si(phi, -1)) { acb_t t; acb_init(t); diff --git a/acb_elliptic/f.c b/acb_elliptic/f.c index 4b591b97..34afd8d7 100644 --- a/acb_elliptic/f.c +++ b/acb_elliptic/f.c @@ -77,8 +77,7 @@ acb_elliptic_f(acb_t res, const acb_t phi, const acb_t m, int times_pi, slong pr return; } - if (times_pi && acb_is_real(phi) && arb_is_exact(acb_realref(phi)) && - arf_is_int_2exp_si(arb_midref(acb_realref(phi)), -1)) + if (times_pi && acb_is_int_2exp_si(phi, -1)) { acb_t t; acb_init(t); diff --git a/acb_elliptic/pi.c b/acb_elliptic/pi.c index e73b31d7..96144e77 100644 --- a/acb_elliptic/pi.c +++ b/acb_elliptic/pi.c @@ -113,9 +113,7 @@ acb_elliptic_pi_inc(acb_t res, const acb_t n, const acb_t phi, const acb_t m, in return; } - if (acb_is_zero(phi) || (times_pi && acb_is_real(phi) - && arb_is_exact(acb_realref(phi)) && - arf_is_int_2exp_si(arb_midref(acb_realref(phi)), -1))) + if (acb_is_zero(phi) || (times_pi && acb_is_int_2exp_si(phi, -1))) { acb_t t; acb_init(t); diff --git a/arb.h b/arb.h index bcccf699..f0f9289c 100644 --- a/arb.h +++ b/arb.h @@ -290,6 +290,13 @@ arb_is_int(const arb_t x) arf_is_int(arb_midref(x)); } +ARB_INLINE int +arb_is_int_2exp_si(const arb_t x, slong e) +{ + return mag_is_zero(arb_radref(x)) && + arf_is_int_2exp_si(arb_midref(x), e); +} + ARB_INLINE int arb_contains_zero(const arb_t x) { diff --git a/doc/source/acb.rst b/doc/source/acb.rst index 923c7ebd..509210b8 100644 --- a/doc/source/acb.rst +++ b/doc/source/acb.rst @@ -225,6 +225,10 @@ Precision and comparisons Returns nonzero iff *z* is an exact integer. +.. function:: int acb_is_int_2exp_si(const acb_t x, slong e) + + Returns nonzero iff *z* exactly equals `n 2^e` for some integer *n*. + .. function:: int acb_equal(const acb_t x, const acb_t y) Returns nonzero iff *x* and *y* are identical as sets, i.e. diff --git a/doc/source/arb.rst b/doc/source/arb.rst index 428f43bf..15c891ca 100644 --- a/doc/source/arb.rst +++ b/doc/source/arb.rst @@ -523,6 +523,10 @@ Comparisons Returns nonzero iff *x* is an exact integer. +.. function:: int arb_is_int_2exp_si(const arb_t x, slong e) + + Returns nonzero iff *x* exactly equals `n 2^e` for some integer *n*. + .. function:: int arb_equal(const arb_t x, const arb_t y) Returns nonzero iff *x* and *y* are equal as balls, i.e. have both the