[test-suite] r196186 - voronoi: Make printing of negative NaNs consistent

Tobias Grosser tobias at grosser.es
Mon Dec 2 17:00:05 PST 2013


Author: grosser
Date: Mon Dec  2 19:00:04 2013
New Revision: 196186

URL: http://llvm.org/viewvc/llvm-project?rev=196186&view=rev
Log:
voronoi: Make printing of negative NaNs consistent

The difference between printing of negative NaNs caused trouble with
the reference output hashes. We now always canonicalize to positive
NaNs.

Modified:
    test-suite/trunk/MultiSource/Benchmarks/Olden/voronoi/output.c

Modified: test-suite/trunk/MultiSource/Benchmarks/Olden/voronoi/output.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/Olden/voronoi/output.c?rev=196186&r1=196185&r2=196186&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/Olden/voronoi/output.c (original)
+++ test-suite/trunk/MultiSource/Benchmarks/Olden/voronoi/output.c Mon Dec  2 19:00:04 2013
@@ -33,8 +33,30 @@ void plot_vedge(p1, p2)
      struct VEC2 p1, p2;
 {
   /* plots a Voronoi-diagram edge on your favorite device. */
-  printf("Vedge %g %g %g %g \n",(float) p1.x, (float) p1.y, (float) p2.x,
-	 (float) p2.y);
+
+  /* Some of the values that are printed can become negative nans
+   * and may, depending on the operating system and libc version,
+   * either be printed as '-nan' or 'nan'.
+   *
+   * The following code ensures we always get positive nans, which
+   * means the hash of the output does not unnecessarily differ
+   * between OS X and linux.
+   */
+  float p1x = p1.x;
+  float p1y = p1.y;
+  float p2x = p2.x;
+  float p2y = p2.y;
+
+  if (isnan(p1x))
+    p1x = copysign(p1x, 1.0);
+  if (isnan(p1y))
+    p1y = copysign(p1y, 1.0);
+  if (isnan(p2x))
+    p2x = copysign(p2x, 1.0);
+  if (isnan(p2y))
+    p2y = copysign(p2y, 1.0);
+
+  printf("Vedge %g %g %g %g \n", p1x, p1y, p2x, p2y);
 }
 
 struct VEC2 circle_center(struct VEC2 a, struct VEC2 b, struct VEC2 c)





More information about the llvm-commits mailing list