ref: 7dbce0093820a01a64d40ce09fee3ef9fecc5f9c
parent: 87f00731e2864debf2efe657de5181fbe5e17a72
author: mag <mag-one@autistici.org>
date: Fri May 26 19:44:46 EDT 2023
bignum?
--- a/builtins.c
+++ b/builtins.c
@@ -222,6 +222,15 @@
FL_T : FL_F;
}
+BUILTIN("bignum?", bignump)
+{
+ argcount(nargs, 1);
+ value_t v = args[0];
+ return ((! isfixnum(v)) ||
+ (iscprim(v) && cp_numtype((cprim_t*)ptr(v)) < T_FLOAT)) ?
+ FL_T : FL_F;
+}
+
BUILTIN("fixnum", fixnum)
{
argcount(nargs, 1);
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -6,10 +6,10 @@
(define (every-int n)
(list (fixnum n) (int8 n) (uint8 n) (int16 n) (uint16 n) (int32 n) (uint32 n)
- (int64 n) (uint64 n)))
+ (int64 n) (uint64 n) (bignum n)))
(define (every-sint n)
- (list (fixnum n) (int8 n) (int16 n) (int32 n) (int64 n)))
+ (list (fixnum n) (int8 n) (int16 n) (int32 n) (int64 n) (bignum n)))
(define (each f l)
(if (atom? l) ()
@@ -82,8 +82,28 @@
(assert (> 9223372036854775808 9223372036854775807))
-; mpint
+; bignum
(assert (> 0x10000000000000000 0x8fffffffffffffff))
+
+(assert (bignum? (ash 2 60)))
+(assert (not (bignum? (- (ash 2 60) 1))))
+(assert (bignum? 1606938044258990275541962092341162602522202993782792835301376))
+
+(assert (= 4764984380238568507752444984131552966909
+ (* 66405897020462343733 71755440315342536873)))
+(assert (= 71755440315342536873
+ (div 4764984380238568507752444984131552966909 66405897020462343733)))
+(assert (= 3203431780337 (div 576460752303423487 179951)))
+(assert (= 3487 (mod 576460752303423487 18000)))
+(assert (= 7 (mod 576460752303423487 10)))
+
+(assert (= 0xffffffffffffffff (logior 0xaaaaaaaaaaaaaaaa 0x5555555555555555)))
+(assert (= 0xaaaaaaaaaaaaaaaa (logxor 0xffffffffffffffff 0x5555555555555555)))
+(assert (= 0xaaaaaaaa (logand 0xaaaaaaaaaaaaaaaa 0x55555555ffffffff)))
+(assert (= 0 (logand 0 0x5555555555555555)))
+;(assert (= 1111222233334444 (ash 11112222333344445555666677778888 -64)))
+;(assert (= 111122223333444455556666777788880000000000000000
+; (ash 11112222333344445555666677778888 64)))
; NaNs
(assert (equal? +nan.0 +nan.0))