Fixed subtraction regression; added new subtraction unit test.

This commit is contained in:
Simon Brooke 2026-02-24 09:08:41 +00:00
parent 62ebaf9819
commit d34d891211
5 changed files with 203 additions and 6 deletions

View file

@ -1,4 +1,9 @@
(set! documentation (lambda (name) (set! documentation (lambda (object)
(:documentation (meta name)))) (cond ((= (type object) "LMDA")
(let (d (nth 3 (source object)))
(cond ((string? d) d)
(t (source object)))))
((member (type object) '("FUNC" "SPFM"))
(:documentation (meta object))))))
(set! doc documentation) (set! doc documentation)

View file

@ -1,3 +1,3 @@
(set! > (lambda (a b) (set! > (lambda (a b)
"`(> a b)`: Return `t` if `a` is a number greater than `b`, else `nil`."
) (not (negative? (- a b)))))

View file

@ -1,3 +1,5 @@
(set! nil? (lambda (o) (= o nil)))
(set! member (lambda (set! member (lambda
(item collection) (item collection)
"Return `t` if this `item` is a member of this `collection`, else `nil`." "Return `t` if this `item` is a member of this `collection`, else `nil`."

View file

@ -257,9 +257,9 @@ struct cons_pointer add_integers( struct cons_pointer a,
debug_print_128bit( rv, DEBUG_ARITH ); debug_print_128bit( rv, DEBUG_ARITH );
debug_print( L"\n", DEBUG_ARITH ); debug_print( L"\n", DEBUG_ARITH );
if ( carry == 0 && ( rv >= 0 || rv < SMALL_INT_LIMIT ) ) { if ( carry == 0 && rv >= 0 && rv < SMALL_INT_LIMIT ) {
result = result =
acquire_integer( ( int64_t ) ( rv & 0xffffffff ), NIL ); acquire_integer( ( int64_t ) ( rv & MAX_INTEGER ), NIL );
break; break;
} else { } else {
struct cons_pointer new = make_integer( 0, NIL ); struct cons_pointer new = make_integer( 0, NIL );

190
unit-tests/subtract.sh Normal file
View file

@ -0,0 +1,190 @@
#!/bin/bash
# Tests for smallnum subtraction
result=0
echo -n "$0: (- 5 4)... "
expected="1"
actual=`echo "(- 5 4)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 5.0 4)... "
expected="1"
actual=`echo "(- 5.0 4)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 5 4.0)... "
expected="1"
actual=`echo "(- 5 4.0)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 5.01 4.0)... "
expected="1.0100000000000000002082"
actual=`echo "(- 5.01 4.0)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 5 4/5)... "
expected="24/5"
actual=`echo "(- 5 4/5)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: max smallint (- 1152921504606846975 1)... "
expected="1,152,921,504,606,846,974"
actual=`echo "(- 1152921504606846975 1)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: max smallint (- 1152921504606846975 1152921504606846974)... "
expected="1"
actual=`echo "(- 1152921504606846975 1152921504606846974)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 4 5)... "
expected="-1"
actual=`echo "(- 4 5)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 4 5.0)... "
expected="-1"
actual=`echo "(- 4 5.0)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 4.0 5)... "
expected="-1"
actual=`echo "(- 4.0 5)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 4.0 5.01)... "
expected="-1.0100000000000000002082"
actual=`echo "(- 4.0 5.01)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: (- 4/5 5)... "
expected="-3/5"
actual=`echo "(- 4/5 5)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: max smallint (- 1 1152921504606846975)... "
expected="-1,152,921,504,606,846,974"
actual=`echo "(- 1 1152921504606846975)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: max smallint (- 1152921504606846974 1152921504606846975)... "
expected="-1"
actual=`echo "(- 1152921504606846974 1152921504606846975)" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
exit ${result}