aboutsummaryrefslogtreecommitdiff
path: root/unit_label.c
blob: 276be912e3508df655ea8e80494c2797a0e26a1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <unistd.h>

#include "unit_label.h"

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;
}