Only taint casereader if case size is unknown.
[pspp] / tests / formats / float-format.sh
1 #! /bin/sh
2
3 # Tests floating-point format conversions.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6
7 # ensure that top_builddir  are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
12
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19
20 cleanup()
21 {
22      cd /
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53 activity="create test program"
54 sed -n \
55     -e 's/#.*//' \
56     -e 's/^[    ]*//' \
57     -e 's/[     ]*$//' \
58     -e '/^$/d' \
59     -e 's/^\(.*\)$/DEBUG FLOAT FORMAT \1./p' \
60     > $TEMPDIR/float-format.pspp <<'EOF'
61 # Each of the tests below checks that conversion between
62 # floating-point formats works correctly.  Comparisons that use ==
63 # require that conversion from any format on the line to any other
64 # format on the line work losslessly.  Comparisons that use => only
65 # check that conversions work losslessly in the given direction.
66
67 # Key to format names:
68 # isl: IEEE single-precision, little endian
69 # isb: IEEE single-precision, big endian
70 # idl: IEEE double-precision, little endian
71 # idb: IEEE double-precision, big endian
72 # vf: VAX F
73 # vd: VAX D
74 # vg: VAX G
75 # zs: Z architecture short
76 # zl: Z architecture long
77 # x: hexadecimal digits
78
79 # IEEE special values.
80  0 == isb(x'00000000')
81 -0 == isb(x'80000000')
82 x('Infinity') == isb(x'7f800000')
83 x('-Infinity') == isb(x'ff800000')
84 x('NaN:') => isb(x'7f800001')           # NaN requires nonzero fraction.
85 x('NaN:e000000000000000') == isb(x'7ff00000') == idb(x'7ffe000000000000')
86 x('NaN:5a5a5e0000000000') == isb(x'7fad2d2f') == idb(x'7ff5a5a5e0000000')
87 x('NaN:975612abcdef4000') == idb(x'7ff975612abcdef4')
88 x('-NaN:e000000000000000') == isb(x'fff00000') == idb(x'fffe000000000000')
89 x('-NaN:5a5a5e0000000000') == isb(x'ffad2d2f') == idb(x'fff5a5a5e0000000')
90 x('-NaN:975612abcdef4000') == idb(x'fff975612abcdef4')
91
92 # PSPP special values.
93 x('Missing') == isb(x'ff7fffff') == idb(x'ffefffffffffffff') == isl(x'ffff7fff') == idl(x'ffffffffffffefff') == vf(x'ffffffff') == vd(x'ffffffffffffffff') == vg(x'ffffffffffffffff') == zs(x'ffffffff') == zl(x'ffffffffffffffff')
94 x('Lowest') == isb(x'ff7ffffe') == idb(x'ffeffffffffffffe') == isl(x'feff7fff') == idl(x'feffffffffffefff') == vf(x'fffffeff') == vd(x'fffffeffffffffff') == vg(x'fffffeffffffffff') == zs(x'fffffffe') == zl(x'fffffffffffffffe')
95 x('Highest') == isb(x'7f7fffff') == idb(x'7fefffffffffffff') == isl(x'ffff7f7f') == idl(x'ffffffffffffef7f') == vf(x'ff7fffff') == vd(x'ffffffffff7fffff') == vg(x'ffffffffff7fffff') == zs(x'7fffffff') == zl(x'7fffffffffffffff')
96
97 # From Wikipedia.
98 0.15625 == isb(b'00111110001000000000000000000000')
99 -118.625 == isb(b'11000010111011010100000000000000')
100
101 # http://www.psc.edu/general/software/packages/ieee/ieee.html
102 x('NaN:0400000000000000') == isb(b'01111111100000100000000000000000')
103 x('-NaN:2225540000000000') == isb(b'11111111100100010001001010101010')
104 2 == isb(b'01000000000000000000000000000000')
105 6.5 == isb(b'01000000110100000000000000000000')
106 -6.5 == isb(b'11000000110100000000000000000000')
107 x('.4p-124') == isb(b'00000000100000000000000000000000')
108 x('.2p-124') == isb(b'00000000010000000000000000000000')
109
110 # Using converter at http://babbage.cs.qc.edu/IEEE-754/Decimal.html
111 # plus Emacs 'calc' to convert decimal to hexadecimal
112 x('.7b74bc6a7ef9db23p8') => isb(x'42f6e979')            # 123.456
113 x('.7b74bc6a7ef9db23p8') => idb(x'405edd2f1a9fbe77')
114 x('.817427d2d4642004p-12') => isb(x'39017428')          # .0001234567
115 x('.817427d2d4642004p-12') => idb(x'3f202e84fa5a8c84')
116 x('.446c3b15f9926688p168') => isb(x'7f800000')          # 1e50; overflow
117 x('.446c3b15f9926688p168') => idb(x'4a511b0ec57e649a')
118
119 # From multiple editions of the z/Architecture Principles of Operation
120 # manual.
121               1.0 == zs(x'41100000') == isb(x'3f800000')
122               0.5 == zs(x'40800000') == isb(x'3f000000')
123        x('.4p-4') == zs(x'3f400000') == isb(x'3c800000')
124                 0 == zs(x'00000000') == isb(x'00000000')
125                -0 == zs(x'80000000') == isb(x'80000000')
126               -15 == zs(x'c1f00000') == isb(x'c1700000')
127 # x('.ffffffp252') == zs(x'7fffffff')
128       x('.3b4p8') == zs(x'423b4000')
129      x('.1p-256') == zs(x'00100000')
130      x('.4p-124') == zs(x'21400000') == isb(x'00800000')
131      x('.8p-148') == zs(x'1b800000') == isb(x'00000001')
132 # x('.ffffffp128') == zs(x'60ffffff') == isb(x'7f7fffff')
133      x('.1p-256') == zs(x'00100000')
134      x('.1p-256') => isb(x'00000000')              # Underflow to zero.
135  x('.ffffffp248') == zs(x'7effffff')
136  x('.ffffffp248') => isb(x'7f800000')              # Overflow to +Infinity.
137
138             x('.4p-1020') => zl(x'0000000000000000')     # Underflow to zero.
139             x('.4p-1020') == idb(x'0010000000000000')
140             x('.4p-1072') => zl(x'0000000000000000')     # Underflow to zero.
141             x('.4p-1072') => idb(x'0000000000000001')
142 x('.fffffffffffff8p1024') => zl(x'7fffffffffffffff')     # Overflow to maxval.
143 x('.fffffffffffff8p1024') => idb(x'7fefffffffffffff')
144             x('.1p-256') == zl(x'0010000000000000') == idb(x'2fb0000000000000')
145  x('.ffffffffffffffp248') == zl(x'7effffffffffffff')
146  x('.ffffffffffffffp248') => idb(x'4f70000000000000')   # Loses precision.
147 EOF
148 if [ $? -ne 0 ] ; then no_result ; fi
149
150 activity="run program"
151 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TEMPDIR/float-format.pspp
152 if [ $? -ne 0 ] ; then fail ; fi
153
154 pass