Remove building with NOCRYPTO option
[minix.git] / lib / libc / gdtoa / test / strtodt.c
blob2983615c04080597c4c5d2d44bd33574a71f0a3a
1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 2001 by Lucent Technologies
6 All Rights Reserved
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
16 permission.
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 THIS SOFTWARE.
27 ****************************************************************/
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30 * with " at " changed at "@" and " dot " changed to "."). */
32 /* Test strtod. */
34 /* On stdin, read triples: d x y:
35 * d = decimal string
36 * x = high-order Hex value expected from strtod
37 * y = low-order Hex value
38 * Complain about errors.
41 #include "gdtoa.h" /* for ULong */
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
46 static int W0, W1;
47 typedef union {
48 double d;
49 ULong L[2];
50 } U;
52 #define UL (unsigned long)
54 static int
55 process(char *fname, FILE *f)
57 U a, b;
58 char buf[2048];
59 char *s, *s1, *se;
60 int line, n;
62 line = n = 0;
64 top:
65 while(fgets(s = buf, sizeof(buf), f)) {
66 line++;
67 while(*s <= ' ')
68 if (!*s++)
69 goto top; /* break 2 */
70 if (*s == '#')
71 continue;
72 while(*s > ' ')
73 s++;
74 /* if (sscanf(s,"\t%lx\t%lx", &a.L[0], &a.L[1]) != 2) */
75 if ((a.L[0] = (ULong)strtoul(s, &s1,16), s1 <= s)
76 || (a.L[1] = (ULong)strtoul(s1,&se,16), se <= s1)) {
77 printf("Badly formatted line %d of %s\n",
78 line, fname);
79 n++;
80 continue;
82 b.d = strtod(buf,0);
83 if (b.L[W0] != a.L[0] || b.L[W1] != a.L[1]) {
84 n++;
85 printf("Line %d of %s: got %lx %lx; expected %lx %lx\n",
86 line, fname, UL b.L[W0], UL b.L[W1], UL a.L[0], UL a.L[1]);
89 return n;
92 int
93 main(int argc, char **argv)
95 FILE *f;
96 char *prog, *s;
97 int n, rc;
98 U u;
100 prog = argv[0];
101 if (argc == 2 && !strcmp(argv[1],"-?")) {
102 fprintf(stderr, "Usage: %s [file [file...]]\n"
103 "\tto read data file(s) of tab-separated triples d x y with\n"
104 "\t\td decimal string\n"
105 "\t\tx = high-order Hex value expected from strtod\n"
106 "\t\ty = low-order Hex value\n"
107 "\tComplain about errors by strtod.\n"
108 "\tIf no files, read triples from stdin.\n",
109 prog);
110 return 0;
113 /* determine endian-ness */
115 u.d = 1.;
116 W0 = u.L[0] == 0;
117 W1 = 1 - W0;
119 /* test */
121 n = rc = 0;
122 if (argc <= 1)
123 n = process("<stdin>", stdin);
124 else
125 while((s = *++argv))
126 if ((f = fopen(s,"r"))) {
127 n += process(s, f);
128 fclose(f);
130 else {
131 rc = 2;
132 fprintf(stderr, "Cannot open %s\n", s);
134 printf("%d bad conversions\n", n);
135 if (n)
136 rc |= 1;
137 return rc;