mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +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
|
(define-c integer-length
|
||||||
"(void* data, int argc, closure _, object k, object x)"
|
"(void* data, int argc, closure _, object k, object x)"
|
||||||
"Cyc_check_int(data, x);
|
"Cyc_check_int(data, x);
|
||||||
int input = (int)unbox_number(x);
|
if (Cyc_is_bignum(x) == boolean_t) {
|
||||||
int res = 0;
|
int res;
|
||||||
while (input) {
|
mp_radix_size(&bignum_value(x), 2, &res);
|
||||||
res++;
|
return_closcall1(data, k, obj_int2obj((res - 1)));
|
||||||
input >>= 1;
|
} else {
|
||||||
};
|
int input = (int)unbox_number(x);
|
||||||
return_closcall1(data, k, obj_int2obj(res));")
|
int res = 0;
|
||||||
|
while (input) {
|
||||||
|
res++;
|
||||||
|
input >>= 1;
|
||||||
|
};
|
||||||
|
return_closcall1(data, k, obj_int2obj(res));
|
||||||
|
}")
|
||||||
|
|
||||||
(define (log2-binary-factors n)
|
(define (log2-binary-factors n)
|
||||||
(- (integer-length (raw-logand n (- n))) 1))
|
(- (integer-length (raw-logand n (- n))) 1))
|
||||||
|
|
Loading…
Add table
Reference in a new issue