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

Neil Girdhar mistersheik at gmail.com
Wed Feb 7 18:49:27 EST 2018


On Wed, Feb 7, 2018 at 6:36 PM Chris Angelico <rosuav at gmail.com> wrote:

> On Thu, Feb 8, 2018 at 10:08 AM, Neil Girdhar <mistersheik at gmail.com>
> wrote:
> >
> > On Wed, Feb 7, 2018 at 5:52 PM Steven D'Aprano <steve at pearwood.info>
> wrote:
> >>
> >> - slower;
> >> - larger errors when converting from decimal numbers (in general);
> >> - larger rounding errors;
> >> - larger wobble;
> >
> >
> > I don't see why it would have any of those problems.  Base 10 isn't
> special
> > in any way.
>
> Base 10 *is* special, because it corresponds to what humans use. In
> binary floating-point, you get weird results (by human standards) like
> 0.1+0.2 not being 0.3; that doesn't happen in decimal.
>
> There is no error when converting from a string of decimal digits to a
> decimal.Decimal, so presumably to avoid error, you'd have to work with
> digits in the same base. The rounding errors and wobble are by
> comparison with binary; you get the same problems in any other base,
> without the benefit of human-friendly behaviour.
>

I see your list was about converting to and from base 10.  That wasn't
really intended in my proposal.  I meant wholly working in another base.
In that sense, 10 isn't particularly "fast, error-free, better at rounding,
etc."

>
> > 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.

>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/twWEvFwahaQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180207/be350afd/attachment.html>


More information about the Python-ideas mailing list