mirror of
https://github.com/ThomasDickey/mawk-snapshots.git
synced 2026-01-27 03:14:29 +00:00
123 lines
2.5 KiB
Bash
Executable File
123 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# $MawkId: fpe_test,v 1.10 2023/11/02 23:20:31 tom Exp $
|
|
###############################################################################
|
|
# copyright 2009-2022,2023, Thomas E. Dickey
|
|
# copyright 2010, Guido Berhoerster
|
|
# copyright 1994,1995, Michael D. Brennan
|
|
#
|
|
# This is a source file for mawk, an implementation of
|
|
# the AWK programming language.
|
|
#
|
|
# Mawk is distributed without warranty under the terms of
|
|
# the GNU General Public License, version 2, 1991.
|
|
###############################################################################
|
|
|
|
# tests if mawk has been compiled to correctly handle
|
|
# floating point exceptions
|
|
|
|
PROG="${MAWK:-../mawk}"
|
|
|
|
: "${EGREP:=grep -E}"
|
|
: "${FGREP:=grep -F}"
|
|
|
|
echo "testing floating point exception handling"
|
|
|
|
STDOUT=${TMPDIR-/tmp}/mawktest$$
|
|
|
|
test1='BEGIN{ print 4/0 }'
|
|
|
|
|
|
test2='BEGIN {
|
|
x = 100
|
|
do { y = x ; x *= 1000 } while ( y != x )
|
|
print "loop terminated"
|
|
}'
|
|
|
|
# this used to test log(-8), but that was too challenging for cygwin hackers
|
|
test3='BEGIN{ print sqrt(-8) }'
|
|
|
|
|
|
echo "testing division by zero"
|
|
echo "$PROG" "$test1"
|
|
$PROG "$test1"
|
|
ret1=$?
|
|
echo
|
|
|
|
echo "testing overflow"
|
|
echo "$PROG" "$test2"
|
|
$PROG "$test2"
|
|
ret2=$?
|
|
echo
|
|
|
|
echo "testing domain error"
|
|
echo "$PROG" "$test3"
|
|
$PROG "$test3" > "$STDOUT"
|
|
ret3=$?
|
|
cat "$STDOUT"
|
|
echo
|
|
|
|
|
|
# the returns should all be zero or all 2
|
|
# core dumps not allowed
|
|
|
|
trap '
|
|
echo compilation defines for floating point are incorrect
|
|
rm -f $STDOUT
|
|
exit 1' 0
|
|
|
|
echo
|
|
echo ==============================
|
|
|
|
echo return1 = $ret1
|
|
echo return2 = $ret2
|
|
echo return3 = $ret3
|
|
|
|
|
|
[ $ret1 -gt 128 ] && { echo test1 failed ; exception=1 ; }
|
|
[ $ret2 -gt 128 ] && { echo test2 failed ; exception=1 ; }
|
|
[ $ret3 -gt 128 ] && { echo test3 failed ; exception=1 ; }
|
|
|
|
[ "$exception" = 1 ] && { rm -f ./*core* "$STDOUT" ; exit 1 ; }
|
|
|
|
|
|
same=0
|
|
|
|
[ $ret1 = $ret2 ] && [ $ret2 = $ret3 ] && same=1
|
|
|
|
|
|
if [ $same = 1 ]
|
|
then
|
|
if [ $ret1 = 0 ]
|
|
then
|
|
echo "results consistent: ignoring floating exceptions"
|
|
# some versions of hpux print NAN as ?
|
|
if $EGREP '[nN][aA][nN]|\?' "$STDOUT" > /dev/null
|
|
then
|
|
:
|
|
# MSYS / MinGW uses a different string...
|
|
elif $FGREP '#IND' "$STDOUT" > /dev/null
|
|
then
|
|
echo "found MinGW hack for NaN..."
|
|
else
|
|
echo "but the library is not IEEE754 compatible"
|
|
echo "test 3 failed"
|
|
exit 1
|
|
fi
|
|
else echo "results consistent: trapping floating exceptions"
|
|
fi
|
|
|
|
trap 0
|
|
rm -f "$STDOUT"
|
|
exit 0
|
|
|
|
else
|
|
cat <<-EOF
|
|
results are not consistent
|
|
return values should all be 0 if ignoring FPEs (e.g. with IEEE754)
|
|
or all 2 if trapping FPEs
|
|
EOF
|
|
|
|
exit 1
|
|
fi
|
|
# vile: ts=4 sw=4
|