source: trunk/essentials/sys-apps/gawk/test/printfloat.awk

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 1.3 KB
Line 
1# Test program for checking sprintf operation with various floating
2# point formats
3#
4# Watch out - full output of this program will have 3000 * tot lines,
5# which will take a chunk of space if you will write it to your disk.
6# --mj
7
8BEGIN {
9 just = "-"
10 plus = "+ "
11 alt = "#"
12 zero = "0"
13 spec = "feEgG"
14 fw[1] = ""
15 fw[2] = "1"
16 fw[3] = "5"
17 fw[4] = "10"
18 fw[5] = "15"
19 prec[1] = ".-1"
20 prec[2] = ""
21 prec[3] = ".2"
22 prec[4] = ".5"
23 prec[5] = ".10"
24
25 num = 123.6
26 factor = 1.0e-12
27 tot = 8
28 data[1] = 0
29 data[2] = 1
30 for (i = 3; i <= tot; i++) {
31 data[i] = num * factor
32 factor *= 1000
33 }
34
35 for (j = 1; j <= 2; j++) {
36 for (p = 1; p <= 3; p++) {
37 for (a = 1; a <= 2; a++) {
38 for (z = 1; z <= 2; z++) {
39 for (s = 1; s <= 5; s++) {
40 for (w = 1; w <= 5; w++) {
41 for (r = 1; r <= 5; r++) {
42 frmt = "|%" substr(just, j, 1)
43 frmt = frmt substr(plus, p, 1)
44 frmt = frmt substr(alt, a, 1)
45 frmt = frmt substr(zero, z, 1)
46 frmt = frmt fw[w] prec[r]
47 frmt = frmt substr(spec, s, 1) "|"
48 for (i = 1; i <= tot; i++) {
49 result = sprintf(frmt, data[i])
50# "normalize" if you must
51# sub(/\|\./, "|0.", result)
52 printf("%-16s %-25s\t%g\n", frmt,
53 result,data[i])
54 }
55 }
56 }
57 }
58 }
59 }
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.