🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49991

Re: Strange floating point results

#49991
From: Jyri Pekkanen
Date: Wed, 24 Nov 1993 20:11
57 lines
2417 bytes
In article <1993Nov24.155323.22771@njitgw.njit.edu>,
Ken Nakata <kxn3796@hertz.njit.edu> wrote:
>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

 Try changing abs() to fabs()

 ... gcc 2.5.4 gives exactly same results as Your VAX cc. 

 /jjp

-- 
	Jyri Pekkanen  :  Jyri.Pekkanen@hut.fi  :  +358-0-513-169
	*  PGP public key available  - f jpekkane@alpha.hut.fi  *
Technical Details
Message-ID: <2d0f57$43t@nntp.hut.fi>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!pipex!sunic!news.funet.fi!nntp.hut.fi!beta.hut.fi!jpekkane
References: <1993Nov24.155323.22771@njitgw.njit.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,456129b01d21acf1
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-11-24 14:56:11 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!pipex!sunic!news.funet.fi!nntp.hut.fi!beta.hut.fi!jpekkane
From: jpekkane@beta.hut.fi (Jyri Pekkanen)
Newsgroups: gnu.gcc.help
Subject: Re: Strange floating point results
Date: 24 Nov 1993 20:11:19 GMT
Organization: Helsinki University of Technology, Finland
Lines: 57
Message-ID: <2d0f57$43t@nntp.hut.fi>
References: <1993Nov24.155323.22771@njitgw.njit.edu>
Reply-To: Jyri.Pekkanen@hut.fi
NNTP-Posting-Host: beta.hut.fi