www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/08/11/19:42:54

From: Kbwms AT aol DOT com
Message-ID: <1dc.f218ef8.2c698135@aol.com>
Date: Mon, 11 Aug 2003 19:31:01 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_1dc.f218ef8.2c698135_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Yet another anomaly?  How can rounding mode change integral output?

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

    printf("Begin with Rounding Mode at Startup\n");
    printf("Demo     = %.3Lf\n", Demo);
    printf("Demo - 1 = %.3Lf\n", DemoM1);

    _control87(RC_UP, RC_UP);

    printf("New Rounding Mode is RC_UP = %.4x\n", RC_UP);
    printf("Demo     = %.3Lf\n", Demo);
    printf("Demo - 1 = %.3Lf\n", DemoM1);
    exit(0);
}
Begin with Rounding Mode at Startup
Demo       = 18446744073709551615.000
Demo - 1 = 18446744073709551613.000

New Rounding Mode is RC_UP = 0800
Demo       = 18446744073709551616.000
Demo - 1 = 18446744073709551615.000

--part1_1dc.f218ef8.2c698135_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">Yet another anomaly?&nbsp; How can rounding mode change=20=
integral output?<BR>
<BR>
#include &lt;stdio.h&gt;<BR>
#include &lt;float.h&gt;<BR>
int<BR>
main(void)<BR>
{<BR>
&nbsp;&nbsp;&nbsp; long double Demo&nbsp;&nbsp; =3D (unsigned long long)(-1)=
;<BR>
&nbsp;&nbsp;&nbsp; long double DemoM1 =3D Demo - 1.0L;<BR>
<BR>
&nbsp;&nbsp;&nbsp; printf("Begin with Rounding Mode at Startup\n");<BR>
&nbsp;&nbsp;&nbsp; printf("Demo&nbsp;&nbsp;&nbsp;&nbsp; =3D %.3Lf\n", Demo);=
<BR>
&nbsp;&nbsp;&nbsp; printf("Demo - 1 =3D %.3Lf\n", DemoM1);<BR>
<BR>
&nbsp;&nbsp;&nbsp; _control87(RC_UP, RC_UP);<BR>
<BR>
&nbsp;&nbsp;&nbsp; printf("New Rounding Mode is RC_UP =3D %.4x\n", RC_UP);<B=
R>
&nbsp;&nbsp;&nbsp; printf("Demo&nbsp;&nbsp;&nbsp;&nbsp; =3D %.3Lf\n", Demo);=
<BR>
&nbsp;&nbsp;&nbsp; printf("Demo - 1 =3D %.3Lf\n", DemoM1);<BR>
&nbsp;&nbsp;&nbsp; exit(0);<BR>
}<BR>
Begin with Rounding Mode at Startup<BR>
Demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D 18446744073709551615.000<BR>
Demo - 1 =3D 18446744073709551613.000<BR>
<BR>
New Rounding Mode is RC_UP =3D 0800<BR>
Demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D 18446744073709551616.000<BR>
Demo - 1 =3D 18446744073709551615.000<BR>
</FONT></HTML>
--part1_1dc.f218ef8.2c698135_boundary--

- Raw text -


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