Git init
[external/mawk.git] / test / fpe_test.v7
1 : tests if mawk has been compiled to correctly handle
2 : floating point exceptions
3
4 test1='BEGIN{ print 4/0 }'
5
6
7 test2='BEGIN { 
8   x = 100
9   do { y = x ; x *= 1000 } while ( y != x )
10   print "loop terminated"
11 }'
12
13 test3='BEGIN{ print log(-8) }'
14
15
16 echo "testing division by zero"
17 echo mawk "$test1"
18 ./mawk "$test1"
19 ret1=$?
20 echo
21
22 echo "testing overflow"
23 echo mawk "$test2"
24 ./mawk "$test2"
25 ret2=$?
26 echo
27
28 echo "testing domain error"
29 echo mawk "$test3"
30 ./mawk "$test3" > temp$$
31 ret3=$?
32 cat temp$$
33 echo
34
35
36 : the returns should all be zero or all 1
37 : core dumps not allowed
38
39 trap '
40 echo compilation defines for floating point are incorrect
41 rm -f temp$$
42 exit 1'  0
43
44 echo
45 echo ==============================
46
47 echo return1 = $ret1
48 echo return2 = $ret2
49 echo return3 = $ret3
50
51
52 [ $ret1 -gt 128 ] && { echo test1 failed ; exception=1 ; }
53 [ $ret2 -gt 128 ] && { echo test2 failed ; exception=1 ; }
54 [ $ret3 -gt 128 ] && { echo test3 failed ; exception=1 ; }
55
56 [ "$exception" = 1 ] && { rm -f core temp$$ ; exit 1 ; }
57
58
59 same=0
60
61 [ $ret1 = $ret2 ] && [ $ret2 = $ret3 ] && same=1
62
63
64 if [ $same = 1 ]
65    then
66    if [ $ret1 = 0 ]
67       then 
68         echo results consistent: ignoring floating exceptions
69         if  grep -i nan temp$$  > /dev/null
70            then :
71            else
72              echo "but the library is not IEEE754 compatible"
73              echo "test 3 failed"
74              exit 1
75         fi
76       else echo results consistent: trapping floating exceptions
77    fi
78
79    trap  0
80    rm -f temp$$
81    exit 0
82
83    else
84    echo results are not consistent
85 echo 'return values should all be 0 if ignoring FPEs (e.g. with IEEE754)
86 or all 1 if trapping FPEs'
87
88 exit 1
89 fi
90