Skip to content

Commit

Permalink
Restore prec_words_to_bits (renamed to prec_pari_to_bits) for backwar…
Browse files Browse the repository at this point in the history
…ds compatibility
  • Loading branch information
antonio-rojas committed Oct 6, 2024
1 parent 3612d39 commit 248f480
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions cypari2/pari_instance.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions cypari2/pari_instance.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 248f480

Please sign in to comment.