home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / MAWK11AS.ZIP / TEST / FPE_TEST < prev    next >
Encoding:
Text File  |  1991-12-18  |  1.7 KB  |  96 lines

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