Article View: gnu.gcc.help
Article #49986Strange floating point results
From: Ken Nakata
Date: Wed, 24 Nov 1993 15:53
Date: Wed, 24 Nov 1993 15:53
50 lines
2300 bytes
2300 bytes
I wrote a program for my VAX assembly class' programming assignment
and it solves simple equations by iteration. C version is following;
-------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
main()
{
double x = 1.0, px;
double y = 2.0, py;
do {
px = x;
py = y;
x = 1.0 + sqrt(px * px + py * py) / 10.0 * cos(py);
y = 2.0 + (sin(px) + sin(py) - px) / 20.0;
} while (abs((x - px) / x) > 1.0e-16 ||
abs((y - py) / y) > 1.0e-16);
printf("x = %17.15lf\ny = %17.15lf\n", x, y);
}
-------------------------------------------------------------------------------
My VAX assembly program agrees with the above C program compiled by cc
on SunOS 4.x.x (sorry don't remember);
x = 0.899475740409558
y = 2.038799794467183
However, the same C program compiled by two versions of gcc (2.4.3 and
2.3.1) don't agree with the above results;
x = 0.906946738485910
y = 2.037538420581679
Gcc 2.4.3 is running on a DECstation/Ultrix and 2.3.1 is running on
Sun Sparc/SunOS 4.x.x (Same program compiled by cc on Ultrix doesn't
get result in reasonable amount of time).
Emacs Calc running on Emacs 18.59 also agrees with my VAX assembly
program (I fed two results to the equations to see if same results
come up).
Why? Is this a bug of gcc?
Thanks in advance.
Ken Nakata
--
* I apologize if there are misused or impolite words or phrases in this
mail or post. They are not intended; I don't fully understand certain
words or nuances of phrasing. Any corrections of English composition
or content would be greatly appreciated. Ken Nakata, CIS, NJIT *
Technical Details
Message-ID:
<1993Nov24.155323.22771@njitgw.njit.edu>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!netnews.upenn.edu!rutgers!njitgw.njit.edu!hertz.njit.edu!kxn3796Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,456129b01d21acf1,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-11-24 10:19:10 PST Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!netnews.upenn.edu!rutgers!njitgw.njit.edu!hertz.njit.edu!kxn3796 From: kxn3796@hertz.njit.edu (Ken Nakata) Newsgroups: gnu.gcc.help Subject: Strange floating point results Message-ID: <1993Nov24.155323.22771@njitgw.njit.edu> Date: 24 Nov 93 15:53:23 GMT Sender: news@njit.edu Organization: New Jersey Institute of Technology, Newark, New Jersey Lines: 50 Nntp-Posting-Host: hertz.njit.edu