diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-03-06 06:10:25 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-03-06 06:10:25 -0800 |
commit | f71e47cda8418d11cef36d874e5d50835ceead02 (patch) | |
tree | 3f292c2353c8dfb318e81989e769afd56c9db2ca /arith.c | |
parent | 0a2923dd24398c24a60c9cd0031c4079b211fdc9 (diff) | |
download | txr-f71e47cda8418d11cef36d874e5d50835ceead02.tar.gz txr-f71e47cda8418d11cef36d874e5d50835ceead02.tar.bz2 txr-f71e47cda8418d11cef36d874e5d50835ceead02.zip |
New function: bignum-len.
* arith.c (bignum_len): Wew function.
(arith_init): Register bignum-len intrinsic.
* arith.h (bignum_len): Declared.
* txr.1: Documented.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -192,6 +192,18 @@ val unum(ucnum u) } } +val bignum_len(val num) +{ + switch (type(num)) { + case CHR: case NUM: + return zero; + case BGNUM: + return unum(mp(num)->used); + default: + type_mismatch(lit("bignum-digits: ~s is not an integer"), num, nao); + } +} + int highest_bit(int_ptr_t n) { #if SIZEOF_PTR == 8 @@ -3089,6 +3101,7 @@ void arith_init(void) reg_varl(intern(lit("*e*"), user_package), flo(M_E)); reg_varl(intern(lit("%e%"), user_package), flo(M_E)); + reg_fun(intern(lit("bignum-len"), user_package), func_n1(bignum_len)); reg_fun(intern(lit("divides"), user_package), func_n2(divides)); reg_fun(intern(lit("bits"), system_package), func_n1(bits)); reg_fun(intern(lit("digpow"), user_package), func_n2o(digpow, 1)); |