aboutsummaryrefslogtreecommitdiff
path: root/unit_label.c
diff options
context:
space:
mode:
Diffstat (limited to 'unit_label.c')
-rw-r--r--unit_label.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/unit_label.c b/unit_label.c
new file mode 100644
index 0000000..22043ee
--- /dev/null
+++ b/unit_label.c
@@ -0,0 +1,23 @@
+#include <unistd.h>
+
+struct unit_label {
+ /* number of times this unit fits into the immediate larger one */
+ double count;
+
+ /* label for the unit*/
+ char *label;
+};
+
+double make_unit_whatsit(const struct unit_label l[], char **unit, double value) {
+ size_t i = 0;
+
+ for (i = 0; l[i+1].label; i++) {
+ if (l[i].count > value) {
+ break;
+ }
+ value /= l[i].count;
+ }
+
+ *unit = l[i].label;
+ return value;
+}