Exemplo n.º 1
0
Arquivo: mid.c Projeto: hroptatyr/ttt
static int
push_beef(char *ln, size_t UNUSED(lz))
{
	char *on;

	/* metronome is up first */
	if (UNLIKELY(strtotv(ln, &on) == NATV)) {
		return -1;
	}

	/* instrument name, don't hash him */
	if (UNLIKELY((on = strchr(++on, '\t')) == NULL)) {
		return -1;
	}
	beg = ++on - ln;

	/* snarf quotes */
	with (const char *str = on) {
		q.b = strtopx(str, &on);
		q.b = on > str ? q.b : NANPX;
	}
Exemplo n.º 2
0
Arquivo: mid.c Projeto: hroptatyr/ttt
	with (const char *str = ++on) {
		q.a = strtopx(str, &on);
		q.a = on > str ? q.a : NANPX;
	}
Exemplo n.º 3
0
 int
main(Void)
{
	char *s, *se, *se1;
	int i, dItry, ndig = 0, r = 1;
	union { long double d; UShort bits[5]; } u, v[2];

	while(s = fgets(ibuf, sizeof(ibuf), stdin)) {
		while(*s <= ' ')
			if (!*s++)
				continue;
		dItry = 0;
		switch(*s) {
		  case 'r':
			r = getround(r, s);
			continue;
		  case 'n':
			i = s[1];
			if (i <= ' ' || i >= '0' && i <= '9') {
				ndig = atoi(s+1);
				continue;
				}
			break; /* nan? */
		  case '#':
			sscanf(s+1, "%hx %hx %hx %hx %hx", &u.bits[_0],
				&u.bits[_1], &u.bits[_2], &u.bits[_3],
				&u.bits[_4]);
			printf("\nInput: %s", ibuf);
			printf(" --> f = #%x %x %x %x %x\n", u.bits[_0],
				u.bits[_1], u.bits[_2], u.bits[_3], u.bits[_4]);
			goto fmt_test;
			}
		dItry = 1;
		printf("\nInput: %s", ibuf);
		i = strtorx(ibuf, &se, r, u.bits);
		if (r == 1 && (i != strtopx(ibuf, &se1, v[0].bits) || se1 != se
		 || memcmp(u.bits, v[0].bits, 10)))
			printf("***strtox and strtorx disagree!!\n:");
		printf("\nstrtox consumes %d bytes and returns %d\n",
				(int)(se-ibuf), i);
		printf("with bits = #%x %x %x %x %x\n",
			u.bits[_0], u.bits[_1], u.bits[_2],
			u.bits[_3], u.bits[_4]);
		if (sizeof(long double) == 12)
			printf("printf(\"%%.21Lg\") gives %.21Lg\n", u.d);
 fmt_test:
		se = g_xfmt(obuf, u.bits, ndig, sizeof(obuf));
		printf("g_xfmt(%d) gives %d bytes: \"%s\"\n\n",
			ndig, (int)(se-obuf), se ? obuf : "<null>");
		if (!dItry)
			continue;
		printf("strtoIx returns %d,",
			strtoIx(ibuf, &se, v[0].bits, v[1].bits));
		printf(" consuming %d bytes.\n", (int)(se-ibuf));
		if (!memcmp(v[0].bits, v[1].bits, 10)) {
			if (!memcmp(u.bits, v[0].bits, 10))
				printf("fI[0] == fI[1] == strtox\n");
			else {
				printf("fI[0] == fI[1] = #%x %x %x %x %x\n",
					v[0].bits[_0], v[0].bits[_1],
					v[0].bits[_2], v[0].bits[_3],
					v[0].bits[_4]);
				if (sizeof(long double) == 12)
				    printf("= %.21Lg\n", v[0].d);
				}
			}
		else {
			printf("fI[0] = #%x %x %x %x %x\n",
					v[0].bits[_0], v[0].bits[_1],
					v[0].bits[_2], v[0].bits[_3],
					v[0].bits[_4]);
			if (sizeof(long double) == 12)
				printf("= %.21Lg\n", v[0].d);
			printf("fI[1] = #%x %x %x %x %x\n",
					v[1].bits[_0], v[1].bits[_1],
					v[1].bits[_2], v[1].bits[_3],
					v[1].bits[_4]);
			if (sizeof(long double) == 12)
				printf("= %.21Lg\n", v[1].d);
			if (!memcmp(v[0].bits, u.bits, 10))
				printf("fI[0] == strtox\n");
			else if (!memcmp(v[1].bits, u.bits, 10))
				printf("fI[1] == strtox\n");
			else
				printf("**** Both differ from strtod ****\n");
			}
		printf("\n");
		}
	return 0;
	}