From 248f4800febc14e360aa7cf9952d998bb719a679 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 6 Oct 2024 22:50:27 +0200 Subject: [PATCH] Restore prec_words_to_bits (renamed to prec_pari_to_bits) for backwards compatibility --- cypari2/pari_instance.pxd | 1 + cypari2/pari_instance.pyx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cypari2/pari_instance.pxd b/cypari2/pari_instance.pxd index 528db5c..2dccd47 100644 --- a/cypari2/pari_instance.pxd +++ b/cypari2/pari_instance.pxd @@ -4,6 +4,7 @@ cimport cython from .gen cimport Gen cpdef long prec_bits_to_pari(unsigned long prec_in_bits) noexcept +cpdef long prec_pari_to_bits(long prec_pari) noexcept cpdef long default_bitprec() noexcept cdef class Pari_auto: diff --git a/cypari2/pari_instance.pyx b/cypari2/pari_instance.pyx index 43ee3c7..4227919 100644 --- a/cypari2/pari_instance.pyx +++ b/cypari2/pari_instance.pyx @@ -366,6 +366,25 @@ cpdef long prec_bits_to_pari(unsigned long prec_in_bits) noexcept: return nbits2prec(prec_in_bits) +cpdef long prec_pari_to_bits(long prec_pari) noexcept: + r""" + Convert from pari real precision to precision + expressed in bits. Note: this adjusts for the two codewords of a + pari real, and is architecture-dependent. + Examples: + >>> from cypari2.pari_instance import prec_words_to_bits + >>> import sys + >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' + >>> prec_words_to_bits(10) == (256 if bitness == '32' else 512) + True + >>> ans32 = [(3, 32), (4, 64), (5, 96), (6, 128), (7, 160), (8, 192), (9, 224)] + >>> ans64 = [(3, 64), (4, 128), (5, 192), (6, 256), (7, 320), (8, 384), (9, 448)] # 64-bit + >>> [(n, prec_words_to_bits(n)) for n in range(3, 10)] == (ans32 if bitness == '32' else ans64) + True + """ + return prec2nbits(prec_pari) + + cpdef long default_bitprec() noexcept: r""" Return the default precision in bits.