Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30985

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

Date 2012-10-08 22:20 -0400
From Dave Angel <d@davea.name>
Subject Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?
References <91ff9b33-c212-4be0-8ed0-1f6b16f56865@googlegroups.com> <5072E7CC.2070405@davea.name> <CAPTjJmons5fwExNOaug0dNsym2eLe5Pduh6cVqynSAPoSowQdQ@mail.gmail.com> <5072EDA6.6040202@davea.name> <k4vvjt$dtr$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.1977.1349749258.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/08/2012 09:45 PM, Terry Reedy wrote:
> On 10/8/2012 11:13 AM, Dave Angel wrote:
>
>>> Isn't it true, though, that Python 3.3 has a completely new
>>> implementation of decimal that largely removes this disadvantage?
>
>> 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
>
> >>> import timeit as tt
> >>> tt.repeat("float('1.0')-float('0.9999999999')")
> [0.6856039948871151, 0.669049830953858, 0.668688006423692]
> >>> tt.repeat("Decimal('1.0')-Decimal('0.9999999999')", "from decimal
> import Decimal")
> [1.3204655578092428, 1.286977575486688, 1.2893188292009938]
>
> >>> tt.repeat("a-b", "a = 1.0; b=0.9999999999")
> [0.06100386171601713, 0.044538539999592786, 0.04451548406098027]
> >>> tt.repeat("a-b", "from decimal import Decimal as D; a = D('1.0');
> b = D('0.9999999999')")
> [0.14685526219517442, 0.12909696344064514, 0.12646059371189722]
>
> A factor of 3, as S. Krah, the cdecimal author, claimed

I concede the point.  But I was "sincere" in my doubt.

What I'm curious about now is 1) how much the various operators vary in
that 3:1 ratio  and 2) how much the overhead portions are using of that
time. 

I have to assume that timeit.repeat doesn't count the time spent in its
second argument, right?  Because converting a string to a Decimal should
be much faster than converting one to float.  But what about the
overhead of eval(), or whatever it uses?  Is the "a-b" converted to byte
code just once?  Or is it recompiled each time through tje loop?

I have to admit not spending much time in timeit();  I usually end up
timing things with my own loops.  So i'd really like to understand how
overhead is figured.

-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? iMath <redstone-cold@163.com> - 2012-10-08 07:07 -0700
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Dave Angel <d@davea.name> - 2012-10-08 10:48 -0400
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Chris Angelico <rosuav@gmail.com> - 2012-10-09 02:00 +1100
    Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm � Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-09 11:39 +0000
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Dave Angel <d@davea.name> - 2012-10-08 11:13 -0400
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-08 16:44 +0200
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Chris Angelico <rosuav@gmail.com> - 2012-10-09 02:19 +1100
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Terry Reedy <tjreedy@udel.edu> - 2012-10-08 21:45 -0400
  Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ? Dave Angel <d@davea.name> - 2012-10-08 22:20 -0400

csiph-web