mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
Bignum NOT operation
This commit is contained in:
parent
37a1d65980
commit
9162e36913
1 changed files with 13 additions and 5 deletions
18
srfi/60.scm
18
srfi/60.scm
|
@ -121,13 +121,21 @@
|
||||||
(define-c lognot
|
(define-c lognot
|
||||||
"(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);
|
||||||
|
alloc_bignum(data, bn);
|
||||||
if (Cyc_is_bignum(x) == boolean_t) {
|
if (Cyc_is_bignum(x) == boolean_t) {
|
||||||
// uh oh, libtommath doesn't provide this!
|
mp_copy(&bignum_value(x), &bignum_value(bn));
|
||||||
Cyc_rt_raise_msg(data, \"bignum negation not supported yet\");
|
|
||||||
} else {
|
} else {
|
||||||
int result = ~((int)unbox_number(x));
|
Cyc_int2bignum((int)unbox_number(x), &bignum_value(bn));
|
||||||
return_closcall1(data, k, obj_int2obj(result));
|
}
|
||||||
}")
|
|
||||||
|
// From https://github.com/libtom/libtommath/issues/30
|
||||||
|
/* A one's complement, aka bitwise NOT, is actually just -a - 1 */
|
||||||
|
//CHECK_ERROR(mp_neg(&op->mp, &out->mp));
|
||||||
|
//CHECK_ERROR(mp_sub_d(&out->mp, 1, &out->mp));
|
||||||
|
mp_neg(&bignum_value(bn), &bignum_value(bn));
|
||||||
|
mp_sub_d(&bignum_value(bn), 1, &bignum_value(bn));
|
||||||
|
return_closcall1(data, k, Cyc_bignum_normalize(data, bn));
|
||||||
|
")
|
||||||
|
|
||||||
(define bitwise-not lognot)
|
(define bitwise-not lognot)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue