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

Steven D'Aprano steve at pearwood.info
Wed Feb 7 17:50:54 EST 2018


On Wed, Feb 07, 2018 at 10:08:50PM +0000, Neil Girdhar wrote:

> Oh, and to answer your specific question, I want to change the way
> arithmetic is done.  I want it to be done in a different radix.

Why?

There are clear advantages to floating point arithmetic done in base 2 
(speed, minimum possible rounding error, least amount of wobble), and a 
different advantage to floating point done in base 10 (matches exactly 
the standard decimal notation used by humans with no conversion error), 
Outside of those two bases, arithmetic done in any other base is going 
to combine the worst of both:

- slower;
- larger errors when converting from decimal numbers (in general);
- larger rounding errors;
- larger wobble;

with no corresponding advantages unless your data is coming to you in 
arbitrary bases.

Doing floating point arithmetic in decimal is already slower and less 
accurate than doing it in binary. I'd like to hear more about your 
use-case for doing it in base 19 or base 7, say, but I would have to 
guess that it is likely to be such a niche use-case that this 
functionality doesn't belong in the standard library.


-- 
Steve


More information about the Python-ideas mailing list