[Bug c/21607] New: Optimizations convert 0 to -0 leading to difference in answers.

2005-05-16 Thread fsmith at mathworks dot com
Hi,

Sorry for the missing information above.  gcc -v did not supply the above 
information and for reasons unknown to me gccbug was not installed on the 
system in question.

Compiling with -O changes the results of this program.

double u_im = 0;

extern double atan(double);
extern int printf(const char *str,...);

int main(void)
{
double y;
double b;

/* Becomes -0 with optimizations and 0 without. */
b = 0 - 3*u_im;

y = atan(-7/b);

printf("b = %g\n",b);
printf("atan(-7/b) = %g\n",y);

if(y >= 0) {
printf("Error happened!\n");
}

return (y>=0);
}

-- 
   Summary: Optimizations convert 0 to -0 leading to difference in
answers.
   Product: gcc
   Version: 3.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fsmith at mathworks dot com
CC: gcc-bugs at gcc dot gnu dot org


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


[Bug c/21607] Optimizations convert 0 to -0 leading to difference in answers.

2005-05-16 Thread fsmith at mathworks dot com

--- Additional Comments From fsmith at mathworks dot com  2005-05-16 13:48 
---
Created an attachment (id=8901)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8901&action=view)
Minimal self-contained C program exhibiting problem

The answer provided by this program changes depending on whether or
not optimizations are turned on.

The reason for the difference is that the value b changes between 0
and -0 depending on the optimization level.

Here is some sample output:
% gcc emtst_asinh_standalone.c
b = 0
atan(-7/b) = -1.5708
% gcc -O emtst_asinh_standalone.c
b = -0
atan(-7/b) = 1.5708
Error happened!


-- 


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


[Bug c/21607] Optimizations convert 0 to -0 leading to difference in answers.

2005-05-16 Thread fsmith at mathworks dot com

--- Additional Comments From fsmith at mathworks dot com  2005-05-16 13:49 
---
Created an attachment (id=8902)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8902&action=view)
Pre-processed version of previous attachment.

Preprocessed version of previous file.  The previous C file was self-contained
so the only benefit you got was deleting my comments.

-- 


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


[Bug c/21607] Optimizations convert 0 to -0 leading to difference in answers.

2005-05-16 Thread fsmith at mathworks dot com

--- Additional Comments From fsmith at mathworks dot com  2005-05-16 13:50 
---
Information from gcc -save-temps -v follows:

Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
 /usr/libexec/gcc/darwin/ppc/3.3/cc1 -E -quiet -v -D__GNUC__=3 -
D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -D__APPLE_CC__=1495 -D__DYNAMIC__ 
emtst_asinh_standalone.c -fPIC -O emtst_asinh_standalone.i
ignoring nonexistent directory "/usr/ppc-darwin/include"
ignoring nonexistent directory "/Local/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include/gcc/darwin/3.3
 /usr/include
End of search list.
Framework search starts here:
 /System/Library/Frameworks
 /Library/Frameworks
End of framework search list.
 /usr/libexec/gcc/darwin/ppc/3.3/cc1 -fpreprocessed emtst_asinh_standalone.i -
fPIC -quiet -dumpbase emtst_asinh_standalone.c -auxbase 
emtst_asinh_standalone -O -version -o emtst_asinh_standalone.s
GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495) (ppc-darwin)
compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 
1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=131072
 /usr/libexec/gcc/darwin/ppc/as -arch ppc -o emtst_asinh_standalone.o 
emtst_asinh_standalone.s
 ld -arch ppc -dynamic -o a.out -lcrt1.o -lcrt2.o -L/usr/lib/gcc/darwin/3.3 -
L/usr/lib/gcc/darwin -L/usr/libexec/gcc/darwin/ppc/3.3/../../.. 
emtst_asinh_standalone.o -lgcc -lSystem |
 c++filt3


-- 
   What|Removed |Added

  GCC build triplet||1495


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


[Bug c/21607] Optimizations convert 0 to -0 leading to difference in answers.

2005-05-16 Thread fsmith at mathworks dot com

--- Additional Comments From fsmith at mathworks dot com  2005-05-16 14:04 
---
How do I report it to Apple?  On their site

http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/gccbug.html#gccbug

they told me to report it here (effectively).  But since, for reasons unknown to
me, gccbug wasn't installed on the MAC I was using I went straight to bugzilla.

-Fred

-- 


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