2 * Copyright © 2011 Nick Bowler
4 * License WTFPL2: Do What The Fuck You Want To Public License, version 2.
5 * This is free software: you are free to do what the fuck you want to.
6 * There is NO WARRANTY, to the extent permitted by law.
15 const char *progname = "dpicalc";
18 simple_strtoul(const char *str, const char *name, int base)
24 ret = strtoul(str, &end, base);
26 fprintf(stderr, "%s: %s: invalid %s: %s\n",
27 progname, str, name, strerror(errno));
29 } else if (*end != '\0') {
30 fprintf(stderr, "%s: %s: invalid %s: trailing garbage\n",
38 int main(int argc, char **argv)
40 double diagonal, ratio, phys_width;
47 fprintf(stderr, "usage: %s diagonal pixel_w pixel_h\n",
52 diagonal = strtod(argv[1], NULL);
53 w = simple_strtoul(argv[2], "pixel width", 10);
54 h = simple_strtoul(argv[3], "pixel height", 10);
56 ratio = (double) h / w;
57 if (!isnormal(ratio)) {
58 fprintf(stderr, "%s: nonsensical aspect ratio (%.2f)\n",
62 phys_width = sqrt(diagonal*diagonal / (1 + ratio*ratio));
63 printf("%.1f\n", w / phys_width);