From 1b73f78249070e277f9fb29bb2853b0c38c3df9e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 4 Feb 2017 17:36:02 -0800 Subject: Add useful sys:bits function. sys:bits converts a Lisp value to an integer whose value is the object's bit pattern interpreted as a pure binary number. (Only the "unboxed" part of the object that is stored in variables or passed into functions, not any "boxded" heap part which is referenced.) this holds: (eq a b) <--> (= (sys:bits a) (sys:bits b)) Two values a and b are the same object iff their sys:bits values are the same integer. * arith.c (bits): New static function. (arith_init): Register bits as sys:bits. --- arith.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arith.c b/arith.c index d5932acb..e1d105e8 100644 --- a/arith.c +++ b/arith.c @@ -2468,6 +2468,12 @@ val width(val obj) uw_throwf(error_s, lit("integer-length: ~s isn't an integer"), obj, nao); } +static val bits(val obj) +{ + return normalize(bignum_from_uintptr(coerce(uint_ptr_t, obj))); +} + + void arith_init(void) { mp_init(&NUM_MAX_MP); @@ -2500,6 +2506,8 @@ void arith_init(void) #endif reg_varl(intern(lit("*e*"), user_package), flo(M_E)); reg_varl(intern(lit("%e%"), user_package), flo(M_E)); + + reg_fun(intern(lit("bits"), system_package), func_n1(bits)); } void arith_free_all(void) -- cgit v1.2.3