[Python-ideas] numerical type combining integer and float/decimal properties [Was: Re: Python Numbers as Human Concept Decimal System]

Guido van Rossum guido at python.org
Mon Mar 10 22:57:48 CET 2014


On Mon, Mar 10, 2014 at 2:51 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Mar 11, 2014 at 7:57 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> > I think he's saying make a new type similarly to complex, only instead of
> > two floats to make a complex number, have a (long) int and a decimal
> float
> > to make this new type.  The long int portion would have infinite
> precision,
> > the float portion would have, say, 16 digits (or whatever).
>
> That's plausible as a representation, and looks tempting, but basic
> arithmetic operations become more complicated. Addition and
> subtraction just need to worry about carries, but multiplication forks
> out into four multiplications (int*int, int*frac, frac*int,
> frac*frac), and division becomes similarly complicated. Would it
> really be beneficial?
>

It looks neither plausible nor tempting to me at all, and I hope that's not
what he meant. It can represent numbers of any magnitude that have lots of
zeros following the decimal point followed by up to 16 digits of precision,
but not numbers that have e.g. lots of ones instead of those zeros -- the
float portion would be used up for the first 16 ones. E.g.

111111111111111111111111111111.000000000000000000000000000000123456789

would be representable exactly but not

111111111111111111111111111111.111111111111111111111111111111123456789

What makes numbers in the vicinity of integers special?

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140310/2487bed8/attachment-0001.html>


More information about the Python-ideas mailing list