Make IEEE754 check more robust
[alexxy/gromacs.git] / cmake / TestFloatFormat.c
index 7467f805a6b5cc4ebc47bfb5d39e19059e1d913a..d0676d5dfa7eb0bde37309de2c721cc9df32e9b0 100644 (file)
@@ -3,8 +3,10 @@ main()
 {
   /* Check that a double is 8 bytes - compilation dies if it isnt */
   extern char xyz [sizeof(double) == 8 ? 1 : -1];
+  int i;
+  double d;
 
-  double abc [] = {
+  double abc [10] = {
     /* Zero-terminated strings encoded as floating-point numbers */
     /* "GROMACSX" in ascii    */
     (double)  3.80279098314984902657e+35 , (double) 0.0,
@@ -18,5 +20,13 @@ main()
     (double) -5.22995989424860458374e+10 , (double) 0.0,
   };
 
-  return 0;
+  /* Make sure some compilers do not optimize away the entire structure
+   * with floating-point data by using it to produce a return value.
+   */
+  for(i=0,d=0;i<10;i++)
+  {
+    d+=abc[i];
+  }
+
+  return (d==12345.0);
 }