brown paper bag bug: replaced 'static char' with std:string as return value
mtk [Tue, 29 Sep 2009 15:29:01 +0000 (15:29 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1461 270642c3-0616-0410-b53a-bc976706d245

senf/Utils/Statistics.cc

index a2363ca..a86f655 100644 (file)
@@ -83,26 +83,31 @@ senf::StatisticsBase::output(unsigned n)
 //
 // generate an engineering style notation 
 //
-char *format_eng( float f)
+std::string format_eng( float f)
 {
-    static char buf[16];
+    char buf[16];
     if (f > 0) {
         int n = 0;
         while( f >= 1000.0f) {
-                f /= 1000.f;
+                f /= 1000.0f;
                 n+=3;
         }
 
-        sprintf( buf, " %3.2fe%+03d", f, n);
+        if( n >=3)
+            sprintf( buf, " %3.2fe%+03d", f, n);
+        else
+            sprintf( buf, "      %3.2f%", f);
     }
     else if (f < 0) {
         int n = 0;
         while( f <= -1000.0f) {
-                f *= 1000.f;
+                f *= 1000.0f;
                 n+=3;
         }
-
-        sprintf( buf, "%3.2fe%+03d", f, n);
+        if( n >=3)
+            sprintf( buf, " %3.2fe%+03d", f, n);
+        else
+            sprintf( buf, "      %3.2f%", f);
     }
     else{
         sprintf( buf, "        0.00");