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