Re: strtod dilemma

Tim Peters (tim@ksr.com)
Mon, 30 May 94 15:16:34 -0400

> ...
> 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!

Of the two, I'd use atof instead of sscanf, just because a simpler
interface is harder for implementers to screw up.

atof & strtod are both std C, but atof long predates the C std so is
available on more platforms. It's hard to imagine that any platform
supports the new strtod but not the old (but still required) atof.

If you verify the format of the string yourself, you're still vulnerable
to poor or incorrect range checking in the implementation, but there's
little you can do about that short of what you already tried to
accomplish with O'Keefe's strtod. Provided atof does it correctly, note
that both overflow & underflow set errno to ERANGE; the difference is
that underflow returns 0. What overflow returns isn't clear (sometimes an
infinity on an IEEE machine; sometimes the largest finite; sometimes
nonsense, although that's definitely an error in the implementation, &
ditto if atof ever blows up).

no-easy-answers-here-ly y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp