[Python-ideas] Consider generalizing Decimal to support arbitrary radix
Case Van Horsen
casevh at gmail.com
Wed Feb 7 19:04:04 EST 2018
On Wed, Feb 7, 2018 at 3:49 PM, Neil Girdhar <mistersheik at gmail.com> wrote:
> On Wed, Feb 7, 2018 at 6:36 PM Chris Angelico <rosuav at gmail.com> wrote:
>> You should be able to use the native float type for binary
>> floating-point. But the whole point of that challenge is that you
>> shouldn't need a computer.
>
>
> Yeah, I know, but I wanted to play with it. Anyway, native floats don't
> help.
>>
>>
>> ChrisA
I maintain gmpy2 and it might do what you want (arbitrary precision
radix-2 arithmetic and easy access to the bits).
>>> gmpy2.get_context().precision=70
>>> gmpy2.mpfr(1)/7
mpfr('0.14285714285714285714283',70)
>>> (gmpy2.mpfr(1)/7).digits(2)
('1001001001001001001001001001001001001001001001001001001001001001001001',
-2, 70)
Historical memory - I once wrote a radix-6 fixed point library to
explore an extension of the 3n+1 problem to rational numbers. It was
written in Turbo Pascal and ran for days on a 286/287 PC.
casevh
More information about the Python-ideas
mailing list