[Python-ideas] Consider generalizing Decimal to support arbitrary radix

Chris Angelico rosuav at gmail.com
Wed Feb 7 18:53:30 EST 2018


On Thu, Feb 8, 2018 at 10:49 AM, Neil Girdhar <mistersheik at gmail.com> wrote:
>> > Right, I was playing with this problem
>> >
>> > (https://brilliant.org/weekly-problems/2017-10-02/advanced/?problem=no-computer-needed)
>> > and wanted to work in base 2.  I realize it's niche, but it's not
>> > exactly a
>> > significant change to the interface even if it's a big change to the
>> > implementation.
>>
>> 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.

Sounds like performance isn't going to be a big problem, then. You can
manage with a non-optimized and naive implementation. So here's a
couple of things to try:

1) Check out PyPI and see if something like what you want exists.
2) Poke around in the source code for the Decimal class (ignore the C
module and use the pure Python one) and see if you can hack on it.

It'd then be off-topic for python-ideas, but it'd be an awesome topic
to discuss on python-list. Exploration is great fun, and Python's a
great language to explore with.

ChrisA


More information about the Python-ideas mailing list