xref: /minix3/lib/libc/gdtoa/test/dItest.c (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc /****************************************************************
2*f14fb602SLionel Sambuc 
3*f14fb602SLionel Sambuc The author of this software is David M. Gay.
4*f14fb602SLionel Sambuc 
5*f14fb602SLionel Sambuc Copyright (C) 1998, 2001 by Lucent Technologies
6*f14fb602SLionel Sambuc All Rights Reserved
7*f14fb602SLionel Sambuc 
8*f14fb602SLionel Sambuc Permission to use, copy, modify, and distribute this software and
9*f14fb602SLionel Sambuc its documentation for any purpose and without fee is hereby
10*f14fb602SLionel Sambuc granted, provided that the above copyright notice appear in all
11*f14fb602SLionel Sambuc copies and that both that the copyright notice and this
12*f14fb602SLionel Sambuc permission notice and warranty disclaimer appear in supporting
13*f14fb602SLionel Sambuc documentation, and that the name of Lucent or any of its entities
14*f14fb602SLionel Sambuc not be used in advertising or publicity pertaining to
15*f14fb602SLionel Sambuc distribution of the software without specific, written prior
16*f14fb602SLionel Sambuc permission.
17*f14fb602SLionel Sambuc 
18*f14fb602SLionel Sambuc LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19*f14fb602SLionel Sambuc INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20*f14fb602SLionel Sambuc IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21*f14fb602SLionel Sambuc SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22*f14fb602SLionel Sambuc WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23*f14fb602SLionel Sambuc IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24*f14fb602SLionel Sambuc ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25*f14fb602SLionel Sambuc THIS SOFTWARE.
26*f14fb602SLionel Sambuc 
27*f14fb602SLionel Sambuc ****************************************************************/
28*f14fb602SLionel Sambuc 
29*f14fb602SLionel Sambuc /* Please send bug reports to David M. Gay (dmg at acm dot org,
30*f14fb602SLionel Sambuc  * with " at " changed at "@" and " dot " changed to ".").	*/
31*f14fb602SLionel Sambuc 
32*f14fb602SLionel Sambuc #include "gdtoaimp.h"
33*f14fb602SLionel Sambuc #include <stdio.h>
34*f14fb602SLionel Sambuc #include <stdlib.h>
35*f14fb602SLionel Sambuc 
36*f14fb602SLionel Sambuc  static char ibuf[2048];
37*f14fb602SLionel Sambuc 
38*f14fb602SLionel Sambuc #define U (unsigned long)
39*f14fb602SLionel Sambuc 
40*f14fb602SLionel Sambuc  static void
41*f14fb602SLionel Sambuc #ifdef KR_headers
dshow(what,d)42*f14fb602SLionel Sambuc dshow(what, d) char *what; double d;
43*f14fb602SLionel Sambuc #else
44*f14fb602SLionel Sambuc dshow(char *what, double d)
45*f14fb602SLionel Sambuc #endif
46*f14fb602SLionel Sambuc {
47*f14fb602SLionel Sambuc 	char buf[32];
48*f14fb602SLionel Sambuc 	g_dfmt(buf, &d, 0, sizeof(buf));
49*f14fb602SLionel Sambuc 	printf("%s = #%lx %lx = %s\n", what,
50*f14fb602SLionel Sambuc 		U ((ULong*)&d)[_0], U ((ULong*)&d)[_1], buf);
51*f14fb602SLionel Sambuc 	}
52*f14fb602SLionel Sambuc 
53*f14fb602SLionel Sambuc  int
main(Void)54*f14fb602SLionel Sambuc main(Void)
55*f14fb602SLionel Sambuc {
56*f14fb602SLionel Sambuc 	/* Input: one number per line */
57*f14fb602SLionel Sambuc 
58*f14fb602SLionel Sambuc 	char *s, *se, *se1;
59*f14fb602SLionel Sambuc 	int i, j;
60*f14fb602SLionel Sambuc 	double dd[2], dd1, dd2;
61*f14fb602SLionel Sambuc 	static char cfmt[] = "%s consumes %d bytes and returns %d\n";
62*f14fb602SLionel Sambuc 
63*f14fb602SLionel Sambuc 	while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) {
64*f14fb602SLionel Sambuc 		while(*s <= ' ')
65*f14fb602SLionel Sambuc 			if (!*s++)
66*f14fb602SLionel Sambuc 				continue;
67*f14fb602SLionel Sambuc 		printf("\nInput: %s", ibuf);
68*f14fb602SLionel Sambuc 		i = strtodI(ibuf, &se, dd);
69*f14fb602SLionel Sambuc 		printf(cfmt, "strtodI", (int)(se-ibuf), i);
70*f14fb602SLionel Sambuc 		dshow("dd[0]", dd[0]);
71*f14fb602SLionel Sambuc 		dshow("dd[1]", dd[1]);
72*f14fb602SLionel Sambuc 		printf("\n");
73*f14fb602SLionel Sambuc 		j = strtoId(ibuf, &se1, &dd1, &dd2);
74*f14fb602SLionel Sambuc 		if (j != i || se != se1
75*f14fb602SLionel Sambuc 		 || dd[0] != dd1 || dd[1] != dd2) {
76*f14fb602SLionel Sambuc 			printf(cfmt, "**** strtoId", (int)(se-ibuf), j);
77*f14fb602SLionel Sambuc 			dshow("dd1", dd1);
78*f14fb602SLionel Sambuc 			dshow("dd2", dd2);
79*f14fb602SLionel Sambuc 			}
80*f14fb602SLionel Sambuc 		}
81*f14fb602SLionel Sambuc 	return 0;
82*f14fb602SLionel Sambuc 	}
83