shithub: femtolisp

Download patch

ref: ced312368fdb879811e25a807fb00782c1f25a45
parent: 7dbce0093820a01a64d40ce09fee3ef9fecc5f9c
author: mag <mag-one@autistici.org>
date: Mon May 29 13:42:56 EDT 2023

ash function and bignums

--- a/cvalues.c
+++ b/cvalues.c
@@ -1532,7 +1532,7 @@
 		accum = ((int64_t)numval(a))<<n;
 		return fits_fixnum(accum) ? fixnum(accum) : return_from_int64(accum);
 	}
-	if(iscprim(a)){
+	if(iscprim(a) || iscvalue(a)){
 		if(n == 0)
 			return a;
 		cp = ptr(a);
@@ -1550,6 +1550,7 @@
 			case T_INT64:  return mk_int64((*(int64_t *)aptr) >> n);
 			case T_UINT64: return mk_uint64((*(uint64_t*)aptr) >> n);
 			case T_MPINT:
+				aptr = cv_data(cp);
 				mp = mpnew(0);
 				mpright(*(mpint**)aptr, n, mp);
 				return mk_mpint(mp);
@@ -1556,8 +1557,9 @@
 			}
 		}
 		if(ta == T_MPINT){
+			aptr = cv_data(cp);
 			mp = mpnew(0);
-			mpleft(*(mpint**)aptr, n, nil);
+			mpleft(*(mpint**)aptr, n, mp);
 			return mk_mpint(mp);
 		}
 		if(ta == T_UINT64)
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -84,10 +84,13 @@
 
 ; bignum
 (assert (> 0x10000000000000000 0x8fffffffffffffff))
+(assert (< 0x8fffffffffffffff 0x10000000000000000))
 
 (assert (bignum? (ash 2 60)))
 (assert (not (bignum? (- (ash 2 60) 1))))
 (assert (bignum? 1606938044258990275541962092341162602522202993782792835301376))
+(assert (bignum? 0xfffffffffffffffff))
+(assert (not (bignum? 0xfffffffffffffff)))
 
 (assert (= 4764984380238568507752444984131552966909
         (* 66405897020462343733 71755440315342536873)))
@@ -97,13 +100,14 @@
 (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)))
+(assert (= 0xfffffffffffffffff (logior 0xaaaaaaaaaaaaaaaaa 0x55555555555555555)))
+(assert (= 0xaaaaaaaaaaaaaaaaa (logxor 0xfffffffffffffffff 0x55555555555555555)))
+(assert (= 0xaaaaaaaaaaaaaaaaa (logxor 0xfffffffffffffffff 0x55555555555555555)))
+(assert (= 0xaaaaaaaaa (logand 0xaaaaaaaaaaaaaaaaa 0x55555555fffffffff)))
+(assert (= 0 (logand 0 0x55555555555555555)))
+(assert (= 602394779747 (ash 11112222333344445555666677778888 -64)))
+(assert (= 204984321473364576635441321909950327706185271083008
+         (ash 11112222333344445555666677778888 64)))
 
 ; NaNs
 (assert (equal? +nan.0 +nan.0))