public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7369: weird results with the statement "#define PI 4.*atan(1.)"
@ 2002-07-21 12:46 gdr
0 siblings, 0 replies; 3+ messages in thread
From: gdr @ 2002-07-21 12:46 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, pel
Synopsis: weird results with the statement "#define PI 4.*atan(1.)"
State-Changed-From-To: open->closed
State-Changed-By: gdr
State-Changed-When: Sun Jul 21 12:46:22 2002
State-Changed-Why:
Not a bug.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7369
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++/7369: weird results with the statement "#define PI 4.*atan(1.)"
@ 2002-07-21 12:36 Andrew Pinski
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2002-07-21 12:36 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/7369; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: pel@ucla.edu
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7369: weird results with the statement "#define PI 4.*atan(1.)"
Date: Sun, 21 Jul 2002 15:26:53 -0400
No you have to use #define PI (4.0*atan(1.))
because if you don't the statement becomes 1/4.*atan(1.0) which is
equal to .25*atan(1.0) not .25*1/atan(1.0).
Please close this bug report the reported behavior is the correct one.
Thanks,
Andrew Pinski
On Sunday, July 21, 2002, at 03:03 , pel@ucla.edu wrote:
>
>> Number: 7369
>> Category: c++
>> Synopsis: weird results with the statement "#define PI
>> 4.*atan(1.)"
>> Confidential: no
>> Severity: non-critical
>> Priority: low
>> Responsible: unassigned
>> State: open
>> Class: sw-bug
>> Submitter-Id: net
>> Arrival-Date: Sun Jul 21 12:06:01 PDT 2002
>> Closed-Date:
>> Last-Modified:
>> Originator: Peter Latham
>> Release: 2.96
>> Organization:
>> Environment:
> Red Hat Linux 7.3
>> Description:
> If PI is defined via the statement
>
> #define PI 4.*atan(1.)
>
> then 1/PI and 1/3.14159 are different.
>> How-To-Repeat:
> compile using "g++ main.c". then type "a.out", which
> prints PI, 1/PI and 1/3.14159. the result is
>
> 3.141593 0.196350 0.318310
>
> If for some strange reasont the file didn't attach properly,
> the source code is:
>
>
> #include <stdio.h>
> #include <math.h>
>
> #define PI 4.*atan(1.)
> //#define PI 3.14159
>
> void main(int argc, char** argv)
> {
> fprintf(stdout, "%f %f %f\n", PI, 1/PI, 1/3.14159);
> }
>
>
>
>
>> Fix:
> the workaround is to not use atan in the define statement,
>
> #define PI=3.14159
>
> this produces the correct output.
>
>> Release-Note:
>> Audit-Trail:
>> Unformatted:
> ----gnatsweb-attachment----
> Content-Type: application/octet-stream; name="main.c"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="main.c"
>
> CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8bWF0aC5oPgoKI2RlZmluZSBQSSA0LiphdGFu
> KDEuKQovLyNkZWZpbmUgUEkgMy4xNDE1OQoKdm9pZCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJn
> dikKewoJZnByaW50ZihzdGRvdXQsICIlZiAlZiAlZlxuIiwgUEksIDEvUEksIDEvMy4xNDE1OSk7
> Cn0K
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* c++/7369: weird results with the statement "#define PI 4.*atan(1.)"
@ 2002-07-21 12:06 pel
0 siblings, 0 replies; 3+ messages in thread
From: pel @ 2002-07-21 12:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 7369
>Category: c++
>Synopsis: weird results with the statement "#define PI 4.*atan(1.)"
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jul 21 12:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Peter Latham
>Release: 2.96
>Organization:
>Environment:
Red Hat Linux 7.3
>Description:
If PI is defined via the statement
#define PI 4.*atan(1.)
then 1/PI and 1/3.14159 are different.
>How-To-Repeat:
compile using "g++ main.c". then type "a.out", which
prints PI, 1/PI and 1/3.14159. the result is
3.141593 0.196350 0.318310
If for some strange reasont the file didn't attach properly,
the source code is:
#include <stdio.h>
#include <math.h>
#define PI 4.*atan(1.)
//#define PI 3.14159
void main(int argc, char** argv)
{
fprintf(stdout, "%f %f %f\n", PI, 1/PI, 1/3.14159);
}
>Fix:
the workaround is to not use atan in the define statement,
#define PI=3.14159
this produces the correct output.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="main.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="main.c"
CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8bWF0aC5oPgoKI2RlZmluZSBQSSA0LiphdGFu
KDEuKQovLyNkZWZpbmUgUEkgMy4xNDE1OQoKdm9pZCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJn
dikKewoJZnByaW50ZihzdGRvdXQsICIlZiAlZiAlZlxuIiwgUEksIDEvUEksIDEvMy4xNDE1OSk7
Cn0K
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-07-21 19:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-21 12:46 c++/7369: weird results with the statement "#define PI 4.*atan(1.)" gdr
-- strict thread matches above, loose matches on Subject: below --
2002-07-21 12:36 Andrew Pinski
2002-07-21 12:06 pel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).