From c74b9cc162024cfb975c217b3895198701ede745 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 18 Jan 2019 13:57:41 +0000 Subject: [PATCH] Bignum subtraction does NOT work Also subtraction of large numbers which are not beyond the bignum barrier does not work. --- unit-tests/bignum-subtract.sh | 116 ++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 unit-tests/bignum-subtract.sh diff --git a/unit-tests/bignum-subtract.sh b/unit-tests/bignum-subtract.sh new file mode 100644 index 0000000..9342913 --- /dev/null +++ b/unit-tests/bignum-subtract.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +##################################################################### +# subtract a smallnum from a smallnum to produce a smallnum +# (right on the boundary) +a=1152921504606846976 +b=1 +expected='1152921504606846975' +output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "subtracting $b from $a: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking no bignum was created: " +grep -v 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi + +##################################################################### +# subtract a smallnum from a bignum to produce a smallnum +# (just over the boundary) +a='1152921504606846977' +b=1 +expected='1152921504606846976' +output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "subtracting $b from $a: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +##################################################################### +# subtract a smallnum from a bignum to produce a smallnum +a='1152921504606846978' +b=1 +expected='1152921504606846977' +output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "subtracting $b from $a: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + + +##################################################################### +# subtract a bignum from a smallnum to produce a negstive smallnum +# (just over the boundary) +a=1 +b=1152921504606846977 +expected='-1152921504606846976' +output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "subtracting $b from $a: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +##################################################################### +# subtract a bignum from a bignum to produce a bignum +a=20000000000000000000 +b=10000000000000000000 +expected=10000000000000000000 +output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "subtracting $b from $a: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi +