7ca4645d4389de441a5f8a59f6defe11503afc80
[pspp] / tests / libpspp / float-format.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl AT_BANNER([floating point formats])
17
18 AT_SETUP([floating point format conversions])
19 AT_DATA([float-format.txt], [dnl
20 # Each of the tests below checks that conversion between
21 # floating-point formats works correctly.  Comparisons that use ==
22 # require that conversion from any format on the line to any other
23 # format on the line work losslessly.  Comparisons that use => only
24 # check that conversions work losslessly in the given direction.
25
26 # Key to format names:
27 # isl: IEEE single-precision, little endian
28 # isb: IEEE single-precision, big endian
29 # idl: IEEE double-precision, little endian
30 # idb: IEEE double-precision, big endian
31 # vf: VAX F
32 # vd: VAX D
33 # vg: VAX G
34 # zs: Z architecture short
35 # zl: Z architecture long
36 # x: hexadecimal digits
37
38 # IEEE special values.
39  0 == isb('00000000')
40 x('Infinity') == isb('7f800000')
41 x('-Infinity') == isb('ff800000')
42 x('NaN:') => isb('7f800001')            # NaN requires nonzero fraction.
43 x('NaN:e000000000000000') == isb('7ff00000') == idb('7ffe000000000000')
44 x('NaN:5a5a5e0000000000') == isb('7fad2d2f') == idb('7ff5a5a5e0000000')
45 x('NaN:975612abcdef4000') == idb('7ff975612abcdef4')
46 x('-NaN:e000000000000000') == isb('fff00000') == idb('fffe000000000000')
47 x('-NaN:5a5a5e0000000000') == isb('ffad2d2f') == idb('fff5a5a5e0000000')
48 x('-NaN:975612abcdef4000') == idb('fff975612abcdef4')
49
50 # PSPP special values.
51 x('Missing') == isb('ff7fffff') == idb('ffefffffffffffff') == isl('ffff7fff') == idl('ffffffffffffefff') == vf('ffffffff') == vd('ffffffffffffffff') == vg('ffffffffffffffff') == zs('ffffffff') == zl('ffffffffffffffff')
52 x('Lowest') == isb('ff7ffffe') == idb('ffeffffffffffffe') == isl('feff7fff') == idl('feffffffffffefff') == vf('fffffeff') == vd('fffffeffffffffff') == vg('fffffeffffffffff') == zs('fffffffe') == zl('fffffffffffffffe')
53 x('Highest') == isb('7f7fffff') == idb('7fefffffffffffff') == isl('ffff7f7f') == idl('ffffffffffffef7f') == vf('ff7fffff') == vd('ffffffffff7fffff') == vg('ffffffffff7fffff') == zs('7fffffff') == zl('7fffffffffffffff')
54
55 # From Wikipedia.
56 0.15625 == isb('3e200000')
57 -118.625 == isb('c2ed4000')
58
59 # http://www.psc.edu/general/software/packages/ieee/ieee.html
60 x('NaN:0400000000000000') == isb('7f820000')
61 x('-NaN:2225540000000000') == isb('ff9112aa')
62 2 == isb('40000000')
63 6.5 == isb('40d00000')
64 -6.5 == isb('c0d00000')
65 x('.4p-124') == isb('00800000')
66 x('.2p-124') == isb('00400000')
67
68 # Using converter at http://babbage.cs.qc.edu/IEEE-754/Decimal.html
69 # plus Emacs 'calc' to convert decimal to hexadecimal
70 x('.7b74bc6a7ef9db23p8') => isb('42f6e979')             # 123.456
71 x('.7b74bc6a7ef9db23p8') => idb('405edd2f1a9fbe77')
72 x('.817427d2d4642004p-12') => isb('39017428')           # .0001234567
73 x('.817427d2d4642004p-12') => idb('3f202e84fa5a8c84')
74 x('.446c3b15f9926688p168') => isb('7f800000')           # 1e50; overflow
75 x('.446c3b15f9926688p168') => idb('4a511b0ec57e649a')
76
77 # From multiple editions of the z/Architecture Principles of Operation
78 # manual.
79               1.0 == zs('41100000') == isb('3f800000')
80               0.5 == zs('40800000') == isb('3f000000')
81        x('.4p-4') == zs('3f400000') == isb('3c800000')
82                 0 == zs('00000000') == isb('00000000')
83                      zs('80000000') == isb('80000000')
84               -15 == zs('c1f00000') == isb('c1700000')
85 # x('.ffffffp252') == zs('7fffffff')
86       x('.3b4p8') == zs('423b4000')
87      x('.1p-256') == zs('00100000')
88      x('.4p-124') == zs('21400000') == isb('00800000')
89      x('.8p-148') == zs('1b800000') == isb('00000001')
90 # x('.ffffffp128') == zs('60ffffff') == isb('7f7fffff')
91      x('.1p-256') == zs('00100000')
92      x('.1p-256') => isb('00000000')              # Underflow to zero.
93  x('.ffffffp248') == zs('7effffff')
94  x('.ffffffp248') => isb('7f800000')              # Overflow to +Infinity.
95
96             x('.4p-1020') => zl('0000000000000000')     # Underflow to zero.
97             x('.4p-1020') == idb('0010000000000000')
98             x('.4p-1072') => zl('0000000000000000')     # Underflow to zero.
99             x('.4p-1072') => idb('0000000000000001')
100 x('.fffffffffffff8p1024') => zl('7fffffffffffffff')     # Overflow to maxval.
101 x('.fffffffffffff8p1024') => idb('7fefffffffffffff')
102             x('.1p-256') == zl('0010000000000000') == idb('2fb0000000000000')
103  x('.ffffffffffffffp248') == zl('7effffffffffffff')
104  x('.ffffffffffffffp248') => idb('4f70000000000000')    # Loses precision.
105 ])
106 AT_CHECK(
107   [sed 's/#.*//
108 s/^[    ]*//
109 s/[     ]*$//
110 /^$/d
111 s/^\(..*\)$/DEBUG FLOAT FORMAT \1./' < float-format.txt > float-format.sps])
112 AT_CHECK([pspp --testing-mode -O format=csv float-format.sps])
113 AT_CLEANUP