Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

Chris Angelico rosuav at gmail.com
Mon Oct 8 11:19:04 EDT 2012


On Tue, Oct 9, 2012 at 2:13 AM, Dave Angel <d at davea.name> wrote:
> On 10/08/2012 11:00 AM, Chris Angelico wrote:
>> On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel <d at davea.name> wrote:
>>> The Decimal class has the disadvantage that it's tons slower on any modern machine I know of...
>> Isn't it true, though, that Python 3.3 has a completely new
>> implementation of decimal that largely removes this disadvantage?
>>
>> ChrisA
>
> I wouldn't know, I'm on 3.2.  However, I sincerely doubt if it's within
> a factor of 100 of the speed of the binary float, at least on
> pentium-class machines that do binary float in microcode. A dozen years
> or so ago, when the IEEE floating point standard was still being formed,
> I tried to argue the committee into including decimal in the standard
> (which they did much later).  Had it been in the standard then, we MIGHT
> have had decimal fp on chip as well as binary.  Then again, the standard
> was roughly based on the already-existing Intel 8087, so maybe it was
> just hopeless.
>
> I guess it's possible that for some operations, the cost of the
> byte-code interpreter and function lookup, etc. might reduce the
> apparent penalty.  Has anybody done any timings?

Try this, from python-dev list:

http://mail.python.org/pipermail/python-dev/2012-September/121832.html

It's not as fast as float, but it sure gives a good account for itself.

ChrisA



More information about the Python-list mailing list