--
---
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
On Thu, Feb 8, 2018 at 10:08 AM, Neil Girdhar <miste...@gmail.com> wrote:
>
> On Wed, Feb 7, 2018 at 5:52 PM Steven D'Aprano <st...@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.
> 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.
ChrisA
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
This is the specialness of base 10
> 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;
> I don't see why it would have any of those problems.
Any base other than 2 has decreased speed (on a binary computer) and
increased computational rounding errors and wobble.
> Base 10 isn't special in any way.
Except as noted above and the fact that computation with binary coded
decimal goes back to the early days of electronic computation.
> with no corresponding advantages unless your data is coming to you in
> arbitrary bases.
> 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.
In cpython, decimal uses _cdecimal for speed. I suspect that 10 is not
only explicitly hard-coded as the base but implicitly hard-coded by
using algorithm tricks that depend on and only work when the base is 10.
--
Terry Jan Reedy
--
Steve
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
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: