[PATCH] test-suite: Fix name clash 'infinity'

robert lytton robert at xmos.com
Fri Jan 24 08:56:02 PST 2014


robertlytton added you to the CC list for the revision "test-suite: Fix name clash 'infinity'".

Rename local variable infinity as infinity_ to prevent clash with std::numeric_limits<T>::infinity().


http://llvm-reviews.chandlerc.com/D2617

Files:
  SingleSource/Benchmarks/Misc-C++/Large/ray.cpp
  SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp

Index: SingleSource/Benchmarks/Misc-C++/Large/ray.cpp
===================================================================
--- SingleSource/Benchmarks/Misc-C++/Large/ray.cpp
+++ SingleSource/Benchmarks/Misc-C++/Large/ray.cpp
@@ -7,7 +7,7 @@
 using namespace std;
 
 numeric_limits<double> real;
-double delta = sqrt(real.epsilon()), infinity = real.infinity();
+double delta = sqrt(real.epsilon()), infinity_ = real.infinity();
 
 struct Vec {
   double x, y, z;
@@ -43,9 +43,9 @@
   double ray_sphere(const Ray &ray) const {
     Vec v = center - ray.orig;
     double b = dot(v, ray.dir), disc = b*b - dot(v, v) + radius * radius;
-    if (disc < 0) return infinity;
+    if (disc < 0) return infinity_;
     double d = sqrt(disc), t2 = b + d;
-    if (t2 < 0) return infinity;
+    if (t2 < 0) return infinity_;
     double t1 = b - d;
     return (t1 > 0 ? t1 : t2);
   }
@@ -79,15 +79,15 @@
 };
 
 Hit intersect(const Ray &ray, const Scene &s)
-{ return s.intersect(Hit(infinity, Vec(0, 0, 0)), ray); }
+{ return s.intersect(Hit(infinity_, Vec(0, 0, 0)), ray); }
 
 double ray_trace(const Vec &light, const Ray &ray, const Scene &s) {
   Hit hit = intersect(ray, s);
-  if (hit.first == infinity) return 0;
+  if (hit.first == infinity_) return 0;
   double g = dot(hit.second, light);
   if (g >= 0) return 0.;
   Vec p = ray.orig + hit.first*ray.dir + delta*hit.second;
-  return (intersect(Ray(p, -1. * light), s).first < infinity ? 0 : -g);
+  return (intersect(Ray(p, -1. * light), s).first < infinity_ ? 0 : -g);
 }
 
 Scene *create(int level, const Vec &c, double r) {
Index: SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp
===================================================================
--- SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp
+++ SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp
@@ -6,7 +6,7 @@
 #define GIMME_SHADOWS  // usage: ./sphereflake [lvl=6] >pix.ppm
 
 enum { childs = 9, ss= 2, ss_sqr = ss*ss }; /* not really tweakable anymore */
-static const double infinity = 1./0, epsilon = 1e-12;
+static const double infinity_ = 1./0, epsilon = 1e-12;
 
 struct v_t{ double x,y,z;v_t(){}
 	v_t(const double a,const double b,const double c):x(a),y(b),z(c){}
@@ -31,7 +31,7 @@
 struct hit_t {
 	v_t n;
 	double t;
-	hit_t():n(v_t(0,0,0)),t(infinity){}
+	hit_t():n(v_t(0,0,0)),t(infinity_){}
 };
 
 struct sphere_t{ 
@@ -43,10 +43,10 @@
 	double intersect(const ray_t&ray)const{
 		const v_t v(o-ray.o); const double b=ray.d.dot(v),disc=b*b-v.magsqr()+r*r;
 		if(disc < 0.)
-			return infinity; /*branch away from the square root*/
+			return infinity_; /*branch away from the square root*/
 		const double d=sqrt(disc), t2=b+d, t1=b-d; /*cond. move*/
 		if(t2 < 0.)
-			return infinity;
+			return infinity_;
 		else
 			return(t1 > 0.? t1 : t2);
 	}
@@ -80,14 +80,14 @@
 static double ray_trace(const node_t*const scene,const ray_t&ray) {
 	hit_t hit;
 	scene->intersect<false>(ray,hit);// trace primary
-	const double diffuse = hit.t==infinity ? 0. : -hit.n.dot(light);
+	const double diffuse = hit.t==infinity_ ? 0. : -hit.n.dot(light);
 	#ifdef GIMME_SHADOWS
 		if (diffuse <= 0.)
 			return 0.;
 		const ray_t sray(ray.o+(ray.d*hit.t)+(hit.n*epsilon),-light);
 		hit_t shit;
 		scene->intersect<true>(sray,shit);// trace shadow
-		return shit.t==infinity ? diffuse : 0.;
+		return shit.t==infinity_ ? diffuse : 0.;
 	#else
 		return diffuse > 0. ? diffuse : 0.;
 	#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2617.1.patch
Type: text/x-patch
Size: 3424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140124/f66e747a/attachment.bin>


More information about the llvm-commits mailing list