mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP - bignums
This commit is contained in:
parent
acbb33cf5b
commit
173109e072
1 changed files with 13 additions and 7 deletions
20
srfi/60.scm
20
srfi/60.scm
|
@ -111,13 +111,19 @@
|
|||
(define-c integer-length
|
||||
"(void* data, int argc, closure _, object k, object x)"
|
||||
"Cyc_check_int(data, x);
|
||||
int input = (int)unbox_number(x);
|
||||
int res = 0;
|
||||
while (input) {
|
||||
res++;
|
||||
input >>= 1;
|
||||
};
|
||||
return_closcall1(data, k, obj_int2obj(res));")
|
||||
if (Cyc_is_bignum(x) == boolean_t) {
|
||||
int res;
|
||||
mp_radix_size(&bignum_value(x), 2, &res);
|
||||
return_closcall1(data, k, obj_int2obj((res - 1)));
|
||||
} else {
|
||||
int input = (int)unbox_number(x);
|
||||
int res = 0;
|
||||
while (input) {
|
||||
res++;
|
||||
input >>= 1;
|
||||
};
|
||||
return_closcall1(data, k, obj_int2obj(res));
|
||||
}")
|
||||
|
||||
(define (log2-binary-factors n)
|
||||
(- (integer-length (raw-logand n (- n))) 1))
|
||||
|
|
Loading…
Add table
Reference in a new issue