🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #1169

Re: Whats wrong with floor()?

#1169
From: Jamshid Afshar
Date: Thu, 20 Aug 1992 22:09
23 lines
1443 bytes
Followups directed to comp.lang.c.

In article <1992Aug16.164006.2345@panix.com> os2man@panix.com (Larry Salomon Jr.) writes:
>>double tmp=33433.740234;
>>printf("%f %f",tmp,floor(tmp));
>>...
>
>This shouldn't have anything to do with it, but %f is for float types.  You
>should be using %lf.

That's a common misconception.  "%f" is correct for either float or
double parameters to printf().  Floats convert to double when passed
to a variadic function (eg, printf(const char*, ...)) or to an
unprototyped function.  In fact, ANSI C doesn't define a "%lf" for
printf(), so the following could crash on a very strict compiler:
	double d = 1.2;
	printf("%lf", d);  // error, "%lf" not valid for printf()
Because its such a common error, though, compilers just ignore the 'l'.

You *must* properly use %lf or %f for *scanf(), though.

Jamshid Afshar
jamshid@emx.utexas.edu
Technical Details
Message-ID: <78104@ut-emx.uucp>
Path: arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!decwrl!mips!swrinde!news.dell.com!math.utexas.edu!ut-emx!jamshid
References: <2118@lunic.luth.se> <1992Aug16.164006.2345@panix.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!decwrl!mips!swrinde!news.dell.com!math.utexas.edu!ut-emx!jamshid
From: jamshid@ut-emx.uucp (Jamshid Afshar)
Newsgroups: comp.os.os2.programmer
Subject: Re: Whats wrong with floor()?
Summary: %lf is not a correct printf() argument specifier
Message-ID: <78104@ut-emx.uucp>
Date: 20 Aug 92 22:09:31 GMT
References: <2118@lunic.luth.se> <1992Aug16.164006.2345@panix.com>
Reply-To: jamshid@emx.utexas.edu
Followup-To: comp.lang.c
Organization: The University of Texas at Austin; Austin, Texas
Lines: 23