diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-02-04 17:36:02 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-02-04 17:36:02 -0800 |
commit | 1b73f78249070e277f9fb29bb2853b0c38c3df9e (patch) | |
tree | a0a20de31c66de88af7e118a1aa29c5c09cc8ead /arith.c | |
parent | d3c59ab2645be91bee1a9ef084997f9c84e54150 (diff) | |
download | txr-1b73f78249070e277f9fb29bb2853b0c38c3df9e.tar.gz txr-1b73f78249070e277f9fb29bb2853b0c38c3df9e.tar.bz2 txr-1b73f78249070e277f9fb29bb2853b0c38c3df9e.zip |
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.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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) |