Article View: comp.sys.amiga.tech
Article #9992C question
From: Lee Sailer
Date: Mon, 10 Oct 1988 18:46
Date: Mon, 10 Oct 1988 18:46
35 lines
1165 bytes
1165 bytes
I have stumbled onto one of those C mystery problems, using Lattice 4.01.
INT_MAX is a #define for the largest int. In my code I have
r1 = 1.0/(double)INT_MAX
and
double im = INT_MAX;
r2 = 1.0/im;
Guess what? r1 and r2 get different values. How come?
This only occurs with FFP. I know it isn't as accurate ,but I didn't
expect it to be crazy.
lee
#include <limits.h>
#include <stdio.h>
main()
{
double r1, r2, r3, im=INT_MAX;
int iim = INT_MAX;
r1 = 1.0/(double)INT_MAX;
r2 = 1.0/im;
r3 = 1.0/(double)iim;
printf("r1 == %g, r2 == %g, r3 == %g.\n", r1, r2, r3);
return 0;
}
With FFP, r1 == r2 != r3. With IEEE, they are equal, and have a
differnt value from either with FFP.
Technical Details
Message-ID:
<56733UH2@PSUVM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!ncar!gatech!psuvax1!psuvm.bitnet!uh2Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!ncar!gatech!psuvax1!psuvm.bitnet!uh2 From: UH2@PSUVM.BITNET (Lee Sailer) Newsgroups: comp.sys.amiga.tech Subject: C question Message-ID: <56733UH2@PSUVM> Date: 10 Oct 88 18:46:58 GMT Organization: Penn State Erie, Behrend College Lines: 33