mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-09 14:07:34 +02:00
Ported bignum_simplify
This commit is contained in:
parent
a956c6fd41
commit
7405969b4a
2 changed files with 17 additions and 12 deletions
21
runtime.c
21
runtime.c
|
@ -2464,21 +2464,21 @@ object C_bignum_simplify(object big)
|
|||
|
||||
switch(length) {
|
||||
case 0:
|
||||
//if (C_in_scratchspacep(C_internal_bignum_vector(big)))
|
||||
// C_mutate_scratch_slot(NULL, C_internal_bignum_vector(big));
|
||||
return obj_int2obj(0);
|
||||
case 1:
|
||||
tmp = *start;
|
||||
if (C_bignum_negativep(big) ?
|
||||
!(tmp & C_INT_SIGN_BIT) && C_fitsinfixnump(-(C_word)tmp) :
|
||||
C_ufitsinfixnump(tmp)) {
|
||||
if (C_in_scratchspacep(C_internal_bignum_vector(big)))
|
||||
C_mutate_scratch_slot(NULL, C_internal_bignum_vector(big));
|
||||
return C_bignum_negativep(big) ? C_fix(-(C_word)tmp) : C_fix(tmp);
|
||||
if (((uint32_t)tmp) <= CYC_FIXNUM_MAX) {
|
||||
if (C_bignum_negativep(big)) {
|
||||
return obj_int2obj(-(int32_t)tmp);
|
||||
} else {
|
||||
return obj_int2obj(tmp);
|
||||
}
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
if (scan < last_digit) C_bignum_mutate_size(big, length);
|
||||
if (scan < last_digit) {
|
||||
C_bignum_size(big) = length;
|
||||
}
|
||||
return big;
|
||||
}
|
||||
}
|
||||
|
@ -2761,8 +2761,7 @@ object bignum2_plus_unsigned(void *data, bignum2_type *x, bignum2_type *y, int n
|
|||
}
|
||||
assert(scan_r <= end_r);
|
||||
|
||||
// TODO: return C_bignum_simplify(result);
|
||||
return result; // TODO: no, could be a fixnum. need to simplify using above!
|
||||
return C_bignum_simplify(result);
|
||||
}
|
||||
|
||||
object Cyc_symbol2string(void *data, object cont, object sym)
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
" object bn1 = Cyc_int2bignum2(data, obj_obj2int(fx1));
|
||||
object bn2 = Cyc_int2bignum2(data, obj_obj2int(fx2));
|
||||
object result = bignum2_plus_unsigned(data, bn1, bn2, 0); // TODO: int negp);
|
||||
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);
|
||||
")
|
||||
(define-c test-bn
|
||||
|
@ -32,10 +37,11 @@
|
|||
(write row)
|
||||
(newline))
|
||||
(list
|
||||
(test-plus #x0FFFffff #x0FFFffff)
|
||||
(test-plus #x2FFFffff #x2FFFffff)
|
||||
(test-plus 1 2)
|
||||
;; TODO: (fixnum? (test-plus 1 2))
|
||||
(test-plus -1 2)
|
||||
(test-plus #x0FFFffff #x0FFFffff)
|
||||
(test-bn 123456789 )
|
||||
(test-bn 123456789 )
|
||||
(test-larger-bn 0 #x0FFF0001 )
|
||||
|
|
Loading…
Add table
Reference in a new issue