1
function display(x, str, i, res) {
1
function display(x,str, i,res) {
2
2
for (i = 0; i < n; i++) {
3
3
if ((res = sprintf(formats[i],x)) != str)
4
4
printf "sprintf(%s,%s) = %s (!= %s)\n",
5
formats[i], x, res, str
11
nan_str = sprintf("%Pf", nan)
12
nnan_str = sprintf("%Pf", -nan)
15
if (nnan_str == "nan")
16
nnan_str = "+" nnan_str
11
nan_str = sprintf("%f",nan)
12
nnan_str = sprintf("%f",-nan)
18
inf_str = "+" sprintf("%Pf", inf)
19
ninf_str = sprintf("%Pf", -inf)
14
inf_str = sprintf("%f",inf)
24
17
formats[n++] = "%f"
25
19
formats[n++] = "%g"
26
20
formats[n++] = "%x"
27
21
formats[n++] = "%d"
30
display(-nan, nnan_str)
32
display(-inf, ninf_str)
34
# Now test uppercase floating-point format strings
35
for (j = 0; j < n; j++)
36
formats[j] = toupper(formats[j])
38
n -= 3 # interger and string formats don't count (%x, %d, %s)
39
nan_str = toupper(nan_str)
40
nnan_str = toupper(nnan_str)
41
inf_str = toupper(inf_str)
42
ninf_str = toupper(ninf_str)
45
display(-nan, nnan_str)
47
display(-inf, ninf_str)
23
display(-nan,nnan_str)
25
display(-inf,"-"inf_str)