strtod dilemma

Guido.van.Rossum@cwi.nl
Mon, 30 May 1994 11:24:11 +0200

Every once in a while I get complaints from someone whose Python
doesn't work because of a faulty assumption about strtod() in my code,
in the Makefile, or (occasionally) in the user's mind. Apaprently
strtod() has not been very stable throughout UNIX releases, and the
error handling of some versions is different from others. Some old
systems don't have it at all. There's a strtod implementation in the
Python distribution but it requires customization, and on Sun hardware
it actually dumps core!

I propose to use a simpler method for converting float literals to
values: atof() or sscanf() with a "%lf" format. After all there are
exactly three calls to strtod() in the whole Python source, and in two
cases the format has already been verified so that no strong error
checking is needed (strop.atof is the third -- I'm willing to fix it).

My question to the forum: does anyone see portability problems with
atof() or sscanf() ? I would guess that these should work on all
systems where strtod() works, but if this isn't the case, I might only
increase my portability problem!

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>