public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35523]  New: Wrong result for constant float expression
@ 2008-03-10 10:37 martin dot apel at simpack dot de
  2008-03-10 10:38 ` [Bug c/35523] " martin dot apel at simpack dot de
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: martin dot apel at simpack dot de @ 2008-03-10 10:37 UTC (permalink / raw)
  To: gcc-bugs

The following expression yields a wrong result, when compiled with gcc 4.3.0

sin(cos(tan(M_PI/2.0)))

The build system is a 64 bit Redhat 5 enterprise Linux machine (kernel 2.6.18)
with a quad-core Q6600 Intel Core 2 processor.

Configure options for gcc are:
onfigured with: ../configure --prefix=/home/home_dev/apel/tools/linux64
--with-gmp=/home/home_dev/apel/tools/linux64
--with-mpfr=/home/home_dev/apel/tools/linux64 --program-suffix=-4.3
--with-gnu-as --with-gnu-ld --with-arch=core2

Command line:
  gcc-4.3 -o test test.c

The preprocessed source file is attached.


-- 
           Summary: Wrong result for constant float expression
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: martin dot apel at simpack dot de
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
@ 2008-03-10 10:38 ` martin dot apel at simpack dot de
  2008-03-10 10:43 ` martin dot apel at simpack dot de
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: martin dot apel at simpack dot de @ 2008-03-10 10:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from martin dot apel at simpack dot de  2008-03-10 10:37 -------
Created an attachment (id=15288)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15288&action=view)
Preprocessed source file producing the bug


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
  2008-03-10 10:38 ` [Bug c/35523] " martin dot apel at simpack dot de
@ 2008-03-10 10:43 ` martin dot apel at simpack dot de
  2008-03-10 15:12 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: martin dot apel at simpack dot de @ 2008-03-10 10:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from martin dot apel at simpack dot de  2008-03-10 10:42 -------
Version information for libgmp: 4.2.2, compiled with gcc-4.2.2
Version information for libmpfr: 2.3.1, compiled with gcc-4.2.2


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
  2008-03-10 10:38 ` [Bug c/35523] " martin dot apel at simpack dot de
  2008-03-10 10:43 ` martin dot apel at simpack dot de
@ 2008-03-10 15:12 ` rguenth at gcc dot gnu dot org
  2008-03-10 16:33 ` martin dot apel at simpack dot de
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-10 15:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2008-03-10 15:12 -------
gcc-4.3 -o t t.i
./t
sin(cos(tan(PI/2))) = -0.280611

gcc-4.3 -o t t.i -fno-builtin -lm
./t
sin(cos(tan(PI/2))) = -0.280611

works for me?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (2 preceding siblings ...)
  2008-03-10 15:12 ` rguenth at gcc dot gnu dot org
@ 2008-03-10 16:33 ` martin dot apel at simpack dot de
  2008-03-10 16:49 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: martin dot apel at simpack dot de @ 2008-03-10 16:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from martin dot apel at simpack dot de  2008-03-10 16:33 -------
(In reply to comment #3)
> gcc-4.3 -o t t.i
> ./t
> sin(cos(tan(PI/2))) = -0.280611
> 
> gcc-4.3 -o t t.i -fno-builtin -lm
> ./t
> sin(cos(tan(PI/2))) = -0.280611
> 
> works for me?
> 

It compiles and runs, but the result is wrong. Using a calculator or gcc-4.2
for the same programs yields a result of -0.8273508412530949929.

Martin


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (3 preceding siblings ...)
  2008-03-10 16:33 ` martin dot apel at simpack dot de
@ 2008-03-10 16:49 ` pinskia at gcc dot gnu dot org
  2008-03-10 16:52 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-03-10 16:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2008-03-10 16:48 -------
On i686:

[pinskia@celery local]$ ~/gcc-local/bin/gcc t.c -fno-builtin -lm -O2
[pinskia@celery local]$ !./
./a.out
sin(cos(tan(PI/2))) = -0.827351
[pinskia@celery local]$ ~/gcc-local/bin/gcc t.c  -lm -O2
[pinskia@celery local]$ !./
./a.out
sin(cos(tan(PI/2))) = -0.280611


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (4 preceding siblings ...)
  2008-03-10 16:49 ` pinskia at gcc dot gnu dot org
@ 2008-03-10 16:52 ` pinskia at gcc dot gnu dot org
  2008-03-10 16:54 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-03-10 16:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2008-03-10 16:52 -------
I also get:
[dandelion:~] pinskia% ./a.out
sin(cos(tan(PI/2))) = -0.280611

Get 4.0.1 on powerpc-darwin.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (5 preceding siblings ...)
  2008-03-10 16:52 ` pinskia at gcc dot gnu dot org
@ 2008-03-10 16:54 ` pinskia at gcc dot gnu dot org
  2008-03-10 17:00 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-03-10 16:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2008-03-10 16:53 -------
(In reply to comment #6)
> I also get:
> [dandelion:~] pinskia% ./a.out
> sin(cos(tan(PI/2))) = -0.280611

In fact this calls the functions:
        fmr f1,f0
        bl L_tan$stub
        fmr f0,f1
        fmr f1,f0
        bl L_cos$stub
        fmr f0,f1
        fmr f1,f0
        bl L_sin$stub
        fmr f0,f1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (6 preceding siblings ...)
  2008-03-10 16:54 ` pinskia at gcc dot gnu dot org
@ 2008-03-10 17:00 ` rguenth at gcc dot gnu dot org
  2008-03-10 17:08 ` rguenth at gcc dot gnu dot org
  2008-03-11  7:59 ` martin dot apel at simpack dot de
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-10 17:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2008-03-10 16:59 -------
Are you sure your calculator isn't wrong? ;)  Gcc 4.2 produces the same result
for me (and only gcc 4.3 constant folds the result).

Of course this might be a glibc issue as indeed the 32bit version produces

./t
sin(cos(tan(PI/2))) = -0.827351

huhm.  For just tan(PI/2) I get

16331778728383844.000000  (32bit)
16331239353195370.000000  (64bit)

which is different enough to make a subsequent (range-reduced) sin or cos
different.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (7 preceding siblings ...)
  2008-03-10 17:00 ` rguenth at gcc dot gnu dot org
@ 2008-03-10 17:08 ` rguenth at gcc dot gnu dot org
  2008-03-11  7:59 ` martin dot apel at simpack dot de
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-10 17:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2008-03-10 17:07 -------
Obviously PI/2 isn't representable exactly here (also not the result, after
all the value is not defined, the value should approach -Inf / +Inf)
Neither ISO C nor IEEE specifies the result for exactly PI/2 (it could be only
NaN IMHO).


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/35523] Wrong result for constant float expression
  2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
                   ` (8 preceding siblings ...)
  2008-03-10 17:08 ` rguenth at gcc dot gnu dot org
@ 2008-03-11  7:59 ` martin dot apel at simpack dot de
  9 siblings, 0 replies; 11+ messages in thread
From: martin dot apel at simpack dot de @ 2008-03-11  7:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from martin dot apel at simpack dot de  2008-03-11 07:58 -------
You are right, tan(PI/2) is undefined. I had this contained in some sort of
unit test comparing the results of my own formula evaluation code
and the result of the compiler. This gave the same result with gcc 4.2, but not
with 4.3. So this is obviously not really a bug, just differing behaviour in
a case, where the behaviour is undefined.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35523


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-03-11  7:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-10 10:37 [Bug c/35523] New: Wrong result for constant float expression martin dot apel at simpack dot de
2008-03-10 10:38 ` [Bug c/35523] " martin dot apel at simpack dot de
2008-03-10 10:43 ` martin dot apel at simpack dot de
2008-03-10 15:12 ` rguenth at gcc dot gnu dot org
2008-03-10 16:33 ` martin dot apel at simpack dot de
2008-03-10 16:49 ` pinskia at gcc dot gnu dot org
2008-03-10 16:52 ` pinskia at gcc dot gnu dot org
2008-03-10 16:54 ` pinskia at gcc dot gnu dot org
2008-03-10 17:00 ` rguenth at gcc dot gnu dot org
2008-03-10 17:08 ` rguenth at gcc dot gnu dot org
2008-03-11  7:59 ` martin dot apel at simpack dot de

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).