diff --git a/library/math/num.lisp b/library/math/num.lisp index 4ff65ea3e..e9590e8df 100644 --- a/library/math/num.lisp +++ b/library/math/num.lisp @@ -191,7 +191,13 @@ (define (- a b) (lisp ,type (a b) - (cl:values (cl:mod (cl:- a b) ,(cl:expt 2 bits))))) + (cl:if (cl:< a b) + (cl:ecase ,bits + (8 255) + (16 65535) + (32 4294967295) + (64 18446744073709551615)) + (cl:values (cl:mod (cl:- a b) ,(cl:expt 2 bits)))))) (define (* a b) (lisp ,type (a b) @@ -199,7 +205,13 @@ (define (fromInt x) (lisp ,type (x) - (cl:values (cl:mod x ,(cl:expt 2 bits)))))))) + (cl:if (cl:minusp x) + (cl:ecase ,bits + (8 255) + (16 65535) + (32 4294967295) + (64 18446744073709551615)) + (cl:values (cl:mod x ,(cl:expt 2 bits))))))))) (coalton-toplevel (define-num-checked Integer cl:identity)