mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15: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
|
||||
"(void* data, int argc, closure _, object k, object x)"
|
||||
"Cyc_check_int(data, x);
|
||||
alloc_bignum(data, bn);
|
||||
if (Cyc_is_bignum(x) == boolean_t) {
|
||||
// uh oh, libtommath doesn't provide this!
|
||||
Cyc_rt_raise_msg(data, \"bignum negation not supported yet\");
|
||||
mp_copy(&bignum_value(x), &bignum_value(bn));
|
||||
} else {
|
||||
int result = ~((int)unbox_number(x));
|
||||
return_closcall1(data, k, obj_int2obj(result));
|
||||
}")
|
||||
Cyc_int2bignum((int)unbox_number(x), &bignum_value(bn));
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue