6
* try all combination of flags and float conversions
7
* with some different widths & precisions
18
static double fmtvals[] = {
19
3.1415925535897932e15,
20
3.1415925535897932e14,
21
3.1415925535897932e13,
22
3.1415925535897932e12,
23
3.1415925535897932e11,
24
3.1415925535897932e10,
35
3.1415925535897932e-1,
36
3.1415925535897932e-2,
37
3.1415925535897932e-3,
38
3.1415925535897932e-4,
39
3.1415925535897932e-5,
40
3.1415925535897932e-6,
41
3.1415925535897932e-7,
42
3.1415925535897932e-8,
43
3.1415925535897932e-9,
44
3.1415925535897932e-10,
45
3.1415925535897932e-11,
46
3.1415925535897932e-12,
47
3.1415925535897932e-13,
48
3.1415925535897932e-14,
49
3.1415925535897932e-15,
53
* are the numbers close?
54
* used to compare long numbers where the last few digits are garbage
55
* due to precision problems
58
numclose(char *num1, char *num2)
64
d1 = fmtstrtod(num1, 0);
65
d2 = fmtstrtod(num2, 0);
71
if (*num1 >= '0' && *num1 <= '9') {
74
if (!(*num2 >= '0' && *num2 <= '9')) {
77
} else if (*num1 != *num2) {
80
} else if (*num1 != *num2) {
82
} else if (*num1 == 'e' || *num1 == 'E') {
94
doit(int just, int plus, int alt, int zero, int width, int prec, int spec)
104
*p++ = "-"[just - 1];
106
*p++ = "+ "[plus - 1];
110
*p++ = "0"[zero - 1];
114
case 1: s = "1"; break;
115
case 2: s = "5"; break;
116
case 3: s = "10"; break;
117
case 4: s = "15"; break;
123
case 1: s = ".0"; break;
124
case 2: s = ".2"; break;
125
case 3: s = ".5"; break;
126
case 4: s = ".15"; break;
131
*p++ = "efgEG"[spec];
134
for (i = 0; i < sizeof(fmtvals) / sizeof(fmtvals[0]); i++) {
135
char ref[1024], buf[1024];
139
sprintf(ref, format, fmtvals[i]);
140
snprint(buf, sizeof(buf), format, fmtvals[i]);
141
if (strcmp(ref, buf) != 0
142
&& !numclose(ref, buf)) {
143
d1 = fmtstrtod(ref, 0);
144
d2 = fmtstrtod(buf, 0);
145
fprintf(stderr, "%s: ref='%s'%s fmt='%s'%s\n",
147
ref, d1==fmtvals[i] ? "" : " (ref is inexact!)",
148
buf, d2==fmtvals[i] ? "" : " (fmt is inexact!)");
152
/* Check again with output to rune string */
153
runesnprint(rbuf, 1024, format, fmtvals[i]);
154
snprint(buf, sizeof(buf), "%S", rbuf);
155
if (strcmp(ref, buf) != 0
156
&& !numclose(ref, buf)) {
157
d1 = fmtstrtod(ref, 0);
158
d2 = fmtstrtod(buf, 0);
159
fprintf(stderr, "%s: ref='%s'%s fmt='%s'%s\n",
161
ref, d1==fmtvals[i] ? "" : " (ref is inexact!)",
162
buf, d2==fmtvals[i] ? "" : " (fmt is inexact!)");
169
main(int argc, char **argv)
171
int just, plus, alt, zero, width, prec, spec;
173
for (just = 0; just < Njust; just++)
174
for (plus = 0; plus < Nplus; plus++)
175
for (alt = 0; alt < Nalt; alt++)
176
for (zero = 0; zero < Nzero; zero++)
177
for (width = 0; width < Nwidth; width++)
178
for (prec = 0; prec < Nprec; prec++)
179
for (spec = 0; spec < Nspec; spec++)
180
doit(just, plus, alt, zero, width, prec, spec);