[MOAB-dev] r1733 - MOAB/trunk/tools/size

tautges at mcs.anl.gov tautges at mcs.anl.gov
Wed Apr 2 09:41:07 CDT 2008


Author: tautges
Date: 2008-04-02 09:41:07 -0500 (Wed, 02 Apr 2008)
New Revision: 1733

Modified:
   MOAB/trunk/tools/size/size.cpp
Log:
Fixing cases reporting nan.



Modified: MOAB/trunk/tools/size/size.cpp
===================================================================
--- MOAB/trunk/tools/size/size.cpp	2008-04-01 18:41:51 UTC (rev 1732)
+++ MOAB/trunk/tools/size/size.cpp	2008-04-02 14:41:07 UTC (rev 1733)
@@ -32,6 +32,8 @@
 #include <termios.h>
 #include <sys/ioctl.h>
 #include <math.h>
+#include <assert.h>
+#include <float.h>
 
 #include "MBCore.hpp"
 #include "MBRange.hpp"
@@ -231,7 +233,9 @@
   struct winsize size;
   if ( ioctl( fileno(stdout), TIOCGWINSZ, (char*)&size ) == 0 )
     term_width = size.ws_col;
-    
+  if (!term_width) term_width = 80;
+  assert(term_width > 7 + type_width + count_width + total_width);
+  
   term_width -= 7; // spaces
   term_width -= type_width;
   term_width -= count_width;
@@ -265,6 +269,12 @@
     
     if (s.count == 0)
       continue;
+
+    double tmp_dbl = s.sqr / s.count - s.sum*s.sum / (double)s.count / (double)s.count;
+    if (tmp_dbl < 0.0) {
+      assert(-tmp_dbl < 100.0*DBL_EPSILON);
+      tmp_dbl = 0.0;
+    }
     
     printf( "%*s %*ld %*.*lg %*.*lg %*.*lg %*.*lg %*.*lg %*.*lg\n",
             type_width, i == MBMAXTYPE ? edge_use_name : MBCN::EntityTypeName(i),
@@ -275,7 +285,7 @@
             val_width, precision, sqrt( s.sqr / s.count ),
             val_width, precision, s.max,
             val_width, precision,  
-            sqrt( s.sqr / s.count - s.sum*s.sum / (double)s.count / (double)s.count )
+            sqrt(tmp_dbl)
           );
   }
   




More information about the moab-dev mailing list