aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-06-18 21:07:28 +1200
committerDavid Phillips <david@sighup.nz>2018-06-18 21:07:28 +1200
commit62aa5397036216480c859849a8d983b7bce5bf47 (patch)
tree092adc17e5e35f775e28e3cbb69101550b99b3aa
parentcd9ad9b08d150535a511cdb91ba6e8139d5b6e81 (diff)
downloadsand-leek-62aa5397036216480c859849a8d983b7bce5bf47.tar.xz
Document make_unit_whatsit with more comment than code
-rw-r--r--unit_label.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/unit_label.c b/unit_label.c
index d163404..b050b89 100644
--- a/unit_label.c
+++ b/unit_label.c
@@ -1,5 +1,22 @@
#include <unistd.h>
+/* Assign *unit a unit string from table unit_label that best fits value.
+ * returns the value reduced by the chosen unit's magnitude
+ *
+ * Tables are worked through in order, stopping at an entry with a falsey
+ * label. While the value is larger than the current unit's maximum count,
+ * the value is divided by this count and the next unit in the table is
+ * examined. Example:
+ * 100 flooby
+ * 500 glargle
+ * 30 lafplop // Can be any count
+ * 0 NULL // Can be any count
+ *
+ * Given this table, a value of:
+ * 150 will store glargle and return 1.5
+ * 50 will store flooby and return 50
+ * 55000 will store lafplop and return 1.1
+ */
double make_unit_whatsit(const struct unit_label l[], char **unit, double value) {
size_t i = 0;