This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/7935: floating point test of ">" fails on -O0, not on -O{1,2,3} for certain values double precision float accessed by operator[] in wrapper class (on ix86)


>Number:         7935
>Category:       c++
>Synopsis:       floating point test of ">"  fails on -O0, not on -O{1,2,3} for certain values double precision float accessed by operator[] in wrapper class (on ix86)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 16 12:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     simon alexander
>Release:        3.2
>Organization:
>Environment:
System: Linux fairway.math.uwaterloo.ca 2.4.18-10 #1 Wed Aug 7 10:26:48 EDT 2002 i686 unknown
Architecture: i686

host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/opt/gcc-3.2 --enable-languages=c,c++,f77
>Description:
in a class wrapping a double[3], for certain values a > test will fail.  The same code using a raw array is correct.  This only occurs for certain values in the array, and only when optimization is turned off "-O0". The simple class in 'foo.cc' below illustrates the problem.
>How-To-Repeat:

[simon@fairway tmp]$ g++ --version
g++ (GCC) 3.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[simon@fairway tmp]$ g++ -O0 foo.cc;./a.out 
in vec3 0.8 is greater than 0.8
in double[3] 0.8 is not greater than 0.8
in vec3 -0.1 is not greater than -0.1
[simon@fairway tmp]$ g++ -O1 foo.cc;./a.out 
in vec3 0.8 is not greater than 0.8
in double[3] 0.8 is not greater than 0.8
in vec3 -0.1 is not greater than -0.1
[simon@fairway tmp]$ 

foo.cc ---
#include <iostream>

class vec3 {
public:
	double operator[](const size_t i) const {return x[i];}
	double& operator[](const size_t i){return x[i];}
private:
	double x[3];
};

int
main(){

 	vec3  u,v;
 	u[0]=u[1]=u[2]=0.9;
 	v[0]=v[1]=v[2]=0.1;

 	std::cout << "in vec3 " << u[0]-v[0] << " is";
 	if ((u[0]-v[0]) > (u[1]-v[1]))
 		;
 	else 
 		std::cout << " not";

 	std::cout << " greater than "  << u[1]-v[1]
 			  << std::endl;
	
	double x[3],y[3];
	x[0]=x[1]=x[2]=0.9;
 	y[0]=y[1]=y[2]=0.1;

 	std::cout << "in double[3] " << x[0]-y[0] << " is";
 	if ((x[0]-y[0]) > (x[1]-y[1]))
 		;
 	else 
 		std::cout << " not";

 	std::cout << " greater than "  << x[1]-y[1]
 			  << std::endl;

	u[0]=u[1]=u[2]=0.0;
 	v[0]=v[1]=v[2]=0.1;

 	std::cout << "in vec3 " << u[0]-v[0] << " is";
 	if ((u[0]-v[0]) > (u[1]-v[1]))
 		;
 	else 
 		std::cout << " not";

 	std::cout << " greater than "  << u[1]-v[1]
 			  << std::endl;		

		
	return 0;
}





>Fix:
unknown.  I'll have a look at the asm output when I have a chance.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]