summaryrefslogtreecommitdiffstats
path: root/src/src/statistics.h
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2015-03-12 12:00:08 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2015-03-12 12:07:10 -0500
commitc903aeab541d6a6d0c41f78d06917523c84c167d (patch)
tree1a7473d58e7d977d41af0ff6f57a401dae1343c8 /src/src/statistics.h
parent7f6ac0ab640e0690d103cca2cd62bc8d99bce645 (diff)
downloadknetstats-c903aeab541d6a6d0c41f78d06917523c84c167d.tar.gz
knetstats-c903aeab541d6a6d0c41f78d06917523c84c167d.zip
Fix counter overflow at 4GB
Add GB range to byte counters
Diffstat (limited to 'src/src/statistics.h')
-rw-r--r--src/src/statistics.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/src/statistics.h b/src/src/statistics.h
index f837768..637b965 100644
--- a/src/src/statistics.h
+++ b/src/src/statistics.h
@@ -1,4 +1,5 @@
/***************************************************************************
+* (c) 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net> *
* Copyright (C) 2004 by Hugo Parente Lima *
* hugo_pl@users.sourceforge.net *
* *
@@ -15,7 +16,7 @@
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
-* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef STATISTICS_H
#define STATISTICS_H
@@ -41,7 +42,7 @@ public:
* \param ksufix Sufix for kilobytes
* \param msufix Sufix for megabytes
*/
- static inline TQString byteFormat( double num, const char* ksufix = " KB", const char* msufix = " MB");
+ static inline TQString byteFormat( double num, const char* ksuffix = " KB", const char* msuffix = " MB", const char* gsuffix = " GB");
void show();
private:
@@ -55,13 +56,19 @@ private slots:
void update();
};
-TQString Statistics::byteFormat( double num, const char* ksufix, const char* msufix ) {
+TQString Statistics::byteFormat( double num, const char* ksuffix, const char* msuffix, const char* gsuffix ) {
const double ONE_KB = 1024.0;
const double ONE_MB = ONE_KB*ONE_KB;
- if ( num >= ONE_MB ) // MB
- return TQString::number( num/(ONE_MB), 'f', 1 ) + msufix;
- else // Kb
- return TQString::number( num/ONE_KB, 'f', 1 ) + ksufix;
+ const double ONE_GB = ONE_KB*ONE_KB*ONE_KB;
+ if ( num >= ONE_GB ) { // GB
+ return TQString::number( num/(ONE_GB), 'f', 1 ) + gsuffix;
+ }
+ else if ( num >= ONE_MB ) { // MB
+ return TQString::number( num/(ONE_MB), 'f', 1 ) + msuffix;
+ }
+ else { // KB
+ return TQString::number( num/ONE_KB, 'f', 1 ) + ksuffix;
+ }
}
#endif