Staging bignum unsigned subraction

This commit is contained in:
Justin Ethier 2022-06-19 10:00:37 -04:00
parent dc139ce2c3
commit 244041c62b
2 changed files with 29 additions and 2 deletions

View file

@ -3167,14 +3167,14 @@ object bignum_minus_unsigned(void *data, object x, object y)
case 0: /* x = y, return 0 */ case 0: /* x = y, return 0 */
return C_fix(0); return C_fix(0);
case -1: /* abs(x) < abs(y), return -(abs(y) - abs(x)) */ case -1: /* abs(x) < abs(y), return -(abs(y) - abs(x)) */
size = C_fix(C_bignum_size(y)); /* Maximum size of result is length of y. */ size = C_bignum_size(y); /* Maximum size of result is length of y. */
size = y; size = y;
y = x; y = x;
x = size; x = size;
break; break;
case 1: /* abs(x) > abs(y), return abs(x) - abs(y) */ case 1: /* abs(x) > abs(y), return abs(x) - abs(y) */
default: default:
size = C_fix(C_bignum_size(x)); /* Maximum size of result is length of x. */ size = C_bignum_size(x); /* Maximum size of result is length of x. */
break; break;
} }

View file

@ -29,6 +29,18 @@ if(is_value_type(result)) {
printf(\"fixnum result\\n\"); printf(\"fixnum result\\n\");
} else if (type_of(result) == bignum2_tag) { } else if (type_of(result) == bignum2_tag) {
printf(\"bignum result\\n\"); printf(\"bignum result\\n\");
}
return_closcall1(data, k, result);
")
(define-c test-minus
"(void *data, int argc, closure _, object k, object fx1, object fx2)"
" object bn1 = Cyc_int2bignum2(data, obj_obj2int(fx1));
object bn2 = Cyc_int2bignum2(data, obj_obj2int(fx2));
object result = bignum_minus_unsigned(data, bn1, bn2);
if(is_value_type(result)) {
printf(\"fixnum result\\n\");
} else if (type_of(result) == bignum2_tag) {
printf(\"bignum result\\n\");
} }
return_closcall1(data, k, result); return_closcall1(data, k, result);
") ")
@ -69,6 +81,21 @@ if(is_value_type(result)) {
(write (test-str2bn "123454354534523454243999" 16)) (write (test-str2bn "123454354534523454243999" 16))
(newline) (newline)
(write "subtraction")
(newline)
(map
(lambda (row)
(write row)
(newline))
(list
(test-minus 1 1)
(test-minus 1 2)
(test-minus -1 2)
(test-minus (- #x0FFFffff) (- #x0FFFffff))
(test-minus (- #x2FFFffff) (- #x2FFFffff))
))
(newline)
(write "multiplication") (write "multiplication")
(newline) (newline)
(map (map