Re: [pypy-svn] r14625 - pypy/dist/pypy/objspace/std
tismer@codespeak.net writes:
Author: tismer Date: Wed Jul 13 17:53:23 2005 New Revision: 14625
Modified: pypy/dist/pypy/objspace/std/strutil.py Log: another less urgent optimization from the train Kiel-Berlin:
refactored string_to_float quite a lot. The issue was raised by Python 2.4's test_long, which caused an overflow in strutil instead of an 1.#inf. I took the chance to rework this quite a little, with the result of - less rounding errors - smaller code - much faster in extreme cases - able to eval float('1.'+10000*'0'+'e-10000') and friends - seems to produce exactly the same as builtin float as far as tested.
Thank you for doing this! The original code was written in about 5 minutes flat...
+ # Usage of long numbers is explicitly avoided, because + # we want to be able to work without longs as a PyPy option.
Unfortunately, the 'input problem for floating point numbers' cannot be solved using arithmetic of any fixed finite precision, see http://citeseer.ist.psu.edu/clinger90how.html for a proof of this. Also, I found a difference between CPython and your code:
strutil.string_to_float('0.099999999999999999') 0.099999999999999992 float('0.099999999999999999') 0.10000000000000001
But still, a vast improvement, thanks! Cheers, mwh -- If comp.lang.lisp *is* what vendors are relying on to make or break Lisp sales, that's more likely the problem than is the effect of any one of us on such a flimsy marketing strategy... -- Kent M Pitman, comp.lang.lisp
Michael Hudson wrote: [hacked on string_to_float]
Thank you for doing this! The original code was written in about 5 minutes flat...
That's in fact very effective! Mine took a bit longer. And as I see, it is still not optimum.
+ # Usage of long numbers is explicitly avoided, because + # we want to be able to work without longs as a PyPy option.
Unfortunately, the 'input problem for floating point numbers' cannot be solved using arithmetic of any fixed finite precision, see
http://citeseer.ist.psu.edu/clinger90how.html
for a proof of this.
Where can I read the full article? Also, I don't understand what the abstract means. I can use double precision integer arithmetic to turn the mantissa and the exponent into a base 2 representation of the given literal in an (as I think) exact way. Well, maybe not if the exponent is negative. Hum.
Also, I found a difference between CPython and your code:
strutil.string_to_float('0.099999999999999999')
0.099999999999999992
Ok, at least identical to what the former code produces. But this doesn't make me so happy.
float('0.099999999999999999')
0.10000000000000001
I thought the way to add digits scaled to the proper power of ten would be optimum. Now I'm no longer sure. In fact, float(stuff) * 10 round up to 1.0, nicely. How comes? Do you have a better strategy? Or is there none a priori, and one would have to add a posteriori adjustments? Is it maybe better to always try to do negative powers after the whole number is loaded in?
But still, a vast improvement, thanks!
well, compared to the time I needed, your's was more efficient. And I'm not happy until it is really perfect. :-] ciao - chris -- Christian Tismer :^) <mailto:tismer@stackless.com> tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
Christian Tismer wrote:
Where can I read the full article?
I was dumb, could read it now. -- Christian Tismer :^) <mailto:tismer@stackless.com> tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
participants (2)
-
Christian Tismer
-
Michael Hudson