diff --git a/lisp/documentation.lisp b/lisp/documentation.lisp index 7c20cf0..22bd9e7 100644 --- a/lisp/documentation.lisp +++ b/lisp/documentation.lisp @@ -1,4 +1,9 @@ -(set! documentation (lambda (name) - (:documentation (meta name)))) +(set! documentation (lambda (object) + (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) diff --git a/lisp/greaterp.lisp b/lisp/greaterp.lisp index 04a48f9..2122ccd 100644 --- a/lisp/greaterp.lisp +++ b/lisp/greaterp.lisp @@ -1,3 +1,3 @@ (set! > (lambda (a b) - -) \ No newline at end of file + "`(> a b)`: Return `t` if `a` is a number greater than `b`, else `nil`." + (not (negative? (- a b))))) \ No newline at end of file diff --git a/lisp/member.lisp b/lisp/member.lisp index 71f5dcf..4fc29cd 100644 --- a/lisp/member.lisp +++ b/lisp/member.lisp @@ -1,3 +1,5 @@ +(set! nil? (lambda (o) (= o nil))) + (set! member (lambda (item collection) "Return `t` if this `item` is a member of this `collection`, else `nil`." diff --git a/src/arith/integer.c b/src/arith/integer.c index 687ff3c..1884a00 100644 --- a/src/arith/integer.c +++ b/src/arith/integer.c @@ -257,9 +257,9 @@ struct cons_pointer add_integers( struct cons_pointer a, debug_print_128bit( rv, 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 = - acquire_integer( ( int64_t ) ( rv & 0xffffffff ), NIL ); + acquire_integer( ( int64_t ) ( rv & MAX_INTEGER ), NIL ); break; } else { struct cons_pointer new = make_integer( 0, NIL ); diff --git a/unit-tests/subtract.sh b/unit-tests/subtract.sh new file mode 100644 index 0000000..2c2e601 --- /dev/null +++ b/unit-tests/subtract.sh @@ -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}