summaryrefslogtreecommitdiffstats
path: root/XUtils.h
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-10-27 18:34:47 +0800
committerBenBE <BenBE@geshi.org>2023-11-24 09:51:25 +0100
commit5751bafb8db06b843a9a79e100751cfcadc09f90 (patch)
tree8771ae3f5c4068b7cf1db3b84de3240b3da1dfbe /XUtils.h
parente34a9fcc8cda01e4a58f59b4a9d990eda8effd60 (diff)
Rewrite Meter_humanUnit() to accept floating point value
Since Meter_humanUnit() is often called with floating point values in Meter objects, rewrite the function to let it process `double` type natively, and save floating point to integer casts. The rewritten function: * Allows higher orders of magnitude including 'R' and 'Q', and addresses infinity. (The previous version has a maximum value of (2^64 - 1) representing 16 ZiB.) * Rounds values when they are in intervals (99.9, 100) and (9.99, 10), and displays them with correct precision (number of fraction digits). * Produces assertion error on negative and NaN values (undefined behavior). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'XUtils.h')
-rw-r--r--XUtils.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/XUtils.h b/XUtils.h
index cfb375cc..afe22112 100644
--- a/XUtils.h
+++ b/XUtils.h
@@ -111,4 +111,7 @@ int compareRealNumbers(double a, double b);
nonnegative. */
double sumPositiveValues(const double* array, size_t count);
+/* IEC unit prefixes */
+static const char unitPrefixes[] = { 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q' };
+
#endif

© 2014-2024 Faster IT GmbH | imprint | privacy policy