Issue 678375: test_long fails - Python tracker (original) (raw)

on linux kernel 2.2.17, libc2.2

this code demonstrates the problem:

s='12345'*1000 float(s)

Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for float(): 1234512...

caused by PyFloat_FromString in floatobject.c: Testing shows strtod only reads the first 721 digits of the string it gets (after any leading zeros). Python then thinks the remaining digits aren't valid because strtod did not process them, even though strtod returned inf as is proper. I guess this is a strtod problem, maybe it depends on the version of libc?

PyFloat_FromString could deal with this case, but really only correctly if it reimpliments strtod, as there could be an exponent way on the end of the string. I don't know what the correct solution to this is, but surely something should at least be done about the failed test.

Logged In: YES user_id=31435

IMO the platform strtod() doesn't conform to the C standard here, and is certainly unreasonable in this case. You should file a bug report against it. (Wheher or not it returns Inf isn't the point here, it's how it sets strtod's **endptr argument -- the standard has clear rules about that).

We're not going to write our own strtod(), so Guido changed the test to use a 600-character string instead. That should hide the symptom for you.