delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/08/10/14:05:32

From: Kbwms AT aol DOT com
Message-ID: <1e0.eca6e87.2c67e363@aol.com>
Date: Sun, 10 Aug 2003 14:05:23 EDT
Subject: Re: Anomaly in printf()
To: djgpp-workers AT delorie DOT com
MIME-Version: 1.0
X-Mailer: 8.0 for Windows sub 6011
Reply-To: djgpp-workers AT delorie DOT com

--part1_1e0.eca6e87.2c67e363_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

In a message dated 8/10/2003 1:50:20 PM Eastern Standard Time, dj AT delorie DOT com 
writes:

> >produces the following (erroneous second line of) output:
> >
> >Demo    = 18446744073709551615
> >Demo - 1 = 18446744073709551613
> >
> >
> >Is this a known problem?
> 
> I've not heard of it.  What happens when you use .3 instead of .0 in
> that format spec?
> 
Behold:

#include <stdio.h>
int
main(void)
{
    long double Demo = (unsigned long long)(-1);

    printf("Demo       = %.3Lf\n", Demo);
    printf("Demo - 1 = %.3Lf\n", Demo-1.0L);
    exit(0);
}
Demo       = 18446744073709551615.000
Demo - 1 = 18446744073709551613.000

--part1_1e0.eca6e87.2c67e363_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<HTML><FONT FACE=3Darial,helvetica><FONT  SIZE=3D3 FAMILY=3D"SERIF" FACE=3D"=
Georgia" LANG=3D"0">In a message dated 8/10/2003 1:50:20 PM Eastern Standard=
 Time, dj AT delorie DOT com writes:<BR>
<BR>
<BLOCKQUOTE TYPE=3DCITE style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT=
: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"></FONT><FONT  COLOR=3D"#000000"=
 style=3D"BACKGROUND-COLOR: #ffffff" SIZE=3D2 FAMILY=3D"SANSSERIF" FACE=3D"A=
rial" LANG=3D"0">&gt;produces the following (erroneous second line of) outpu=
t:<BR>
&gt;<BR>
&gt;Demo&nbsp;&nbsp;&nbsp; =3D 18446744073709551615<BR>
&gt;Demo - 1 =3D 18446744073709551613<BR>
&gt;<BR>
&gt;<BR>
&gt;Is this a known problem?<BR>
<BR>
I've not heard of it.&nbsp; What happens when you use .3 instead of .0 in<BR=
>
that format spec?<BR>
</BLOCKQUOTE><BR>
</FONT><FONT  COLOR=3D"#000000" style=3D"BACKGROUND-COLOR: #ffffff" SIZE=3D3=
 FAMILY=3D"SERIF" FACE=3D"Georgia" LANG=3D"0">Behold:<BR>
<BR>
#include &lt;stdio.h&gt;<BR>
int<BR>
main(void)<BR>
{<BR>
&nbsp;&nbsp;&nbsp; long double Demo =3D (unsigned long long)(-1);<BR>
<BR>
&nbsp;&nbsp;&nbsp; printf("Demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D %.3L=
f\n", Demo);<BR>
&nbsp;&nbsp;&nbsp; printf("Demo - 1 =3D %.3Lf\n", Demo-1.0L);<BR>
&nbsp;&nbsp;&nbsp; exit(0);<BR>
}<BR>
Demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D 18446744073709551615.000<BR>
Demo - 1 =3D 18446744073709551613.000<BR>
</FONT></HTML>
--part1_1e0.eca6e87.2c67e363_boundary--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019