Article View: can.usrgroup
Article #295C code (fwd)
From: Steve Bird
Date: Wed, 28 Feb 1990 13:38
Date: Wed, 28 Feb 1990 13:38
35 lines
1177 bytes
1177 bytes
Forwarded message:
>From steve Fri Nov 24 21:46:23 1989
Subject: C code
To: evan@telly (Evan Leibovitch)
Date: Fri, 24 Nov 89 21:46:23 EST
From: Steve Bird <steve@cohort.UUCP>
X-Mailer: ELM [version 2.2 PL7]
Here's another interesting piece.
/* floaterr.c--demonstrates round-off error */
# include <stdio.h>
main()
{
float a,b;
b = 2.0e20 + 1.0;
a = b - 2.0e20;
printf("%f \n",a);
}
When compiled the program returns the number 4008175468544.000000 .
Now when the program is modified to read :
/* floaterr.c--demonstrates round-off error */
# include <stdio.h>
main()
{
float a,b;
b = 2.0e20 + 1.0;
a = 2.0e20;
printf("%f \n",b - a);
}
The program returns 0.000000 . Why ?
Technical Details
Message-ID:
<9002280838.AA01415@cohort.uucp>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!geac!torsqnt!tmsoft!list-injectorShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!geac!torsqnt!tmsoft!list-injector From: steve@cohort.UUCP (Steve Bird) Newsgroups: can.usrgroup Subject: C code (fwd) Message-ID: <9002280838.AA01415@cohort.uucp> Date: 28 Feb 90 13:38:06 GMT Reply-To: Steve Bird <steve@cohort.UUCP> Distribution: ont Lines: 35 X-Mailer: ELM [version 2.2 PL7]