ok@quintus.UUCP (Richard A. O'Keefe) (12/27/89)
The railroad diagram on page 163 of "Standard C" by Plauger & Brodie suggests that the string argument of strtod() must contain either a decimal point or an exponent, so that strtod("1234", (char**)NULL) must return 0.0 if called in the "C" locale. This requirement matches the syntax of floating-point constants in C, but it is more restrictive than current versions of strtod(), which accept "1234". Q1: have Plauger & Brodie got it right? Q2: if they have got it right, why does the standard prohibit "1234" in *data*?
henry@utzoo.uucp (Henry Spencer) (12/31/89)
In article <1294@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >The railroad diagram on page 163 of "Standard C" by Plauger & Brodie >suggests that the string argument of strtod() must contain either a >decimal point or an exponent, so that strtod("1234", (char**)NULL) >must return 0.0 if called in the "C" locale. This requirement matches >the syntax of floating-point constants in C, but it is more restrictive >than current versions of strtod(), which accept "1234". > >Q1: have Plauger & Brodie got it right? P&B have goofed. The description of strtod in the draft (well, the Oct 88 draft, the one I've got) specifies that both decimal point and exponent are optional, and explicitly assigns a meaning to the case where neither is present. For a guess, P&B copied the diagram from the floating-point-constant one and overlooked the fine print. -- 1972: Saturn V #15 flight-ready| Henry Spencer at U of Toronto Zoology 1989: birds nesting in engines | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
gwyn@smoke.BRL.MIL (Doug Gwyn) (01/05/90)
In article <1294@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >Q1: have Plauger & Brodie got it right? No; they oversimplified. The railroad-track syntax should be applied AFTER conceptually editing the subject sequence to insert a decimal point after its last digit. The actual X3.159 specification of strtod() is rather elaborate, but that was necessary in order to get details like this right. The simplification leaves out some essential details. "1234" is successfully converted by strtod(), which returns 1234.0.