diff --git a/README.md b/README.md index 8c7baa90..b3ff1f02 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,8 @@ CHANGELOG ------------- Next release: - +- [gh-160](https://github.com/flintlib/python-flint/pull/160) + Add `bits` to `arb` and `acb`, add `log_base` to `arb`. - [gh-148](https://github.com/flintlib/python-flint/pull/148) Remove debug symbols to make smaller Linux binaries. - [gh-144](https://github.com/flintlib/python-flint/pull/144) diff --git a/src/flint/flintlib/arb.pxd b/src/flint/flintlib/arb.pxd index d9e54b69..e0887ff9 100644 --- a/src/flint/flintlib/arb.pxd +++ b/src/flint/flintlib/arb.pxd @@ -183,6 +183,7 @@ cdef extern from "flint/arb.h": void arb_log_ui(arb_t z, ulong x, long prec) void arb_log_fmpz(arb_t z, const fmpz_t x, long prec) void arb_log1p(arb_t z, const arb_t x, long prec) + void arb_log_base_ui(arb_t z, const arb_t x, ulong b, long prec) void arb_exp(arb_t z, const arb_t x, long prec) void arb_expm1(arb_t z, const arb_t x, long prec) void arb_sin(arb_t s, const arb_t x, long prec) diff --git a/src/flint/types/acb.pyx b/src/flint/types/acb.pyx index 074c210a..bb2bd6e6 100644 --- a/src/flint/types/acb.pyx +++ b/src/flint/types/acb.pyx @@ -1403,6 +1403,14 @@ cdef class acb(flint_scalar): def rel_one_accuracy_bits(self): return acb_rel_one_accuracy_bits(self.val) + def bits(self): + r"""Returns maximum of :meth:`.arb.bits` called on real and imaginary part. + + >>> acb("2047/2048").bits() + 11 + """ + return acb_bits(self.val) + def ei(s): r""" Exponential integral `\operatorname{Ei}(s)`. diff --git a/src/flint/types/arb.pyx b/src/flint/types/arb.pyx index 50274775..ad84c41c 100644 --- a/src/flint/types/arb.pyx +++ b/src/flint/types/arb.pyx @@ -809,6 +809,16 @@ cdef class arb(flint_scalar): arb_log1p((u).val, (s).val, getprec()) return u + def log_base(s, ulong b): + r"""Returns `\log_b(s)`, computed exactly when possible. + + >>> arb(2048).log_base(2) + 11.0000000000000 + """ + u = arb.__new__(arb) + arb_log_base_ui((u).val, (s).val, b, getprec()) + return u + def sin(s): r""" Sine function `\sin(s)`. @@ -2416,6 +2426,14 @@ cdef class arb(flint_scalar): def rel_one_accuracy_bits(self): return arb_rel_one_accuracy_bits(self.val) + def bits(self): + r"""Returns number of bits needed to represent absolute value of mantissa of the midpoint; returns 0 if midpoint is special value. + + >>> arb("2047/2048").bits() + 11 + """ + return arb_bits(self.val) + def lambertw(s, int branch=0): r""" Lambert *W* function, `W_k(s)`. Either the principal