[pypy-dev] Re: [pypy-svn] r14625 - pypy/dist/pypy/objspace/std
Christian Tismer
tismer at stackless.com
Wed Jul 13 19:53:28 CEST 2005
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 at 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/
More information about the pypy-dev
mailing list