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 Content-Type: multipart/alternative; boundary="part1_1dc.f218ef8.2c698135_boundary" 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 #include 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 Yet another anomaly?  How can rounding mode change=20= integral output?

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

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

    _control87(RC_UP, RC_UP);

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

New Rounding Mode is RC_UP =3D 0800
Demo       =3D 18446744073709551616.000
Demo - 1 =3D 18446744073709551615.000
--part1_1dc.f218ef8.2c698135_boundary--