Using SCANF with DOUBLE precisi

karl at haddock karl at haddock
Wed Oct 1 01:31:00 AEST 1986


ucsfcgl!kneller (Don Kneller) writes:
>In article <22 at orion.UUCP> vaughan at orion.UUCP (Robert Vaughan) writes:
>>scanf("%lf",&foo);
>Except, of course, in the infinite wisdom of Silicon Graphics whose
>floats and doubles are the same size so one must use %f for both.  The
>"justification" is that they have yet another floating point type called
>long float with gets the %lf format.  It's painfully nonportable.  Sigh.

Then it isn't a C compiler and/or library.

Do you really mean "long float"?  In K&R that's a synonym for "double"; ANSI
removed this and added "long double" for which the format is "%Lf" (note
uppercase L).  The elegant solution would've been "short float" (formerly
"float"), format "%hf"; "float" (formerly double), format "%f"; and "long
float" (what ANSI calls "long double"), format "%lf", but elegance must defer
to compatibility.  Sigh.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list