Lines Matching +full:n +full:- +full:factor

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
55 double factor;
163 lineptr += strspn(lineptr, " \n\t");
164 len = strcspn(lineptr, " \n\t");
168 if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */
173 lineptr[strlen(lineptr) - 1] = 0;
182 lineptr += strspn(lineptr, " \n\t");
183 len = strcspn(lineptr, "\n\t");
205 lineptr += strspn(lineptr, " \n\t");
211 len = strcspn(lineptr, "\n\t");
222 theunit->numerator[0] = theunit->denominator[0] = NULL;
223 theunit->factor = 1.0;
224 theunit->offset = 0.0;
225 theunit->quantity = 0;
253 printf(numfmt, theunit->factor);
254 if (theunit->offset)
255 printf("&%.8g", theunit->offset);
256 for (ptr = theunit->numerator; *ptr; ptr++) {
257 if (ptr > theunit->numerator && **ptr &&
258 !strcmp(*ptr, *(ptr - 1)))
272 for (ptr = theunit->denominator; *ptr; ptr++) {
273 if (ptr > theunit->denominator && **ptr &&
274 !strcmp(*ptr, *(ptr - 1)))
290 printf("\n");
321 if (*slash == '-' &&
322 (tolower(*(slash - 1)) != 'e' ||
330 item = strtok(scratch, " *\t\n/");
336 theunit->quantity = 1;
355 theunit->factor *= num;
356 theunit->offset *= num;
358 theunit->factor /= num;
359 theunit->offset /= num;
368 theunit->factor /= num;
369 theunit->offset /= num;
371 theunit->factor *= num;
372 theunit->offset *= num;
383 theunit->factor *= num;
384 theunit->offset *= num;
386 theunit->factor /= num;
387 theunit->offset /= num;
391 theunit->offset += offsetnum;
397 item[strlen(item) - 1])) {
398 repeat = item[strlen(item) - 1] - '0';
399 item[strlen(item) - 1] = 0;
401 for (; repeat; repeat--) {
402 if (addsubunit(doingtop ^ flip ? theunit->numerator : theunit->denominator, item)) {
408 item = strtok(NULL, " *\t/\n");
410 doingtop--;
415 doingtop--;
435 for (count = 0, ptr = theunit->numerator; *ptr; ptr++, count++);
436 qsort(theunit->numerator, count, sizeof(char *), compare);
437 for (count = 0, ptr = theunit->denominator; *ptr; ptr++, count++);
438 qsort(theunit->denominator, count, sizeof(char *), compare);
448 den = theunit->denominator;
449 num = theunit->numerator;
489 if (unit[strlen(unit) - 1] == '^') {
491 copy[strlen(copy) - 1] = 0;
500 } else if (unit[strlen(unit) - 1] == 's') {
502 copy[strlen(copy) - 1] = 0;
510 if (copy[strlen(copy) - 1] == 'e') {
511 copy[strlen(copy) - 1] = 0;
558 product = theunit->denominator;
560 product = theunit->numerator;
569 printf("unknown unit '%s'\n", *product);
636 compareproducts(first->numerator, second->numerator) ||
637 compareproducts(first->denominator, second->denominator);
658 printf("conformability error\n");
672 else if (have->offset != want->offset) {
673 if (want->quantity)
674 printf("WARNING: conversion of non-proportional quantities.\n");
675 if (have->quantity) {
676 asprintf(&oformat, "\t%s\n", outputformat);
678 (have->factor + have->offset-want->offset)/want->factor);
682 asprintf(&oformat, "\t (-> x*%sg %sg)\n\t (<- y*%sg %sg)\n",
685 have->factor / want->factor,
686 (have->offset-want->offset)/want->factor,
687 want->factor / have->factor,
688 (want->offset - have->offset)/have->factor);
692 ans = have->factor / want->factor;
698 printf("\n");
702 printf("\n");
707 printf("\n");
713 printf(") * %s\n", wantstr);
718 printf("\n");
728 "usage: units [-ehqtUVv] [-f unitsfile] [-o format] [from to]\n");
737 {"output-format", required_argument, NULL, 'o'},
765 while ((optchar = getopt_long(argc, argv, "+ehf:o:qtvH:UV", longopts, NULL)) != -1) {
793 fprintf(stderr, "FreeBSD units\n");
797 printf("%s\n", UNITSFILE);
812 if (optind == argc - 2) {
841 printf("%d units, %d prefixes\n", unitcount,