shithub: femtolisp

Download patch

ref: 41f2177eb490e4e8844cc289a94531d7b9736eac
parent: 9d1884599c62a813514f29c0bf033db1fee7e650
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Apr 2 20:10:21 EDT 2023

use more stuff from math.h

--- a/flisp.c
+++ b/flisp.c
@@ -408,7 +408,8 @@
 			*pcdr = nc = tagptr((cons_t*)curheap, TAG_CONS);
 			curheap += sizeof(cons_t);
 			d = cdr_(v);
-			car_(v) = TAG_FWD; cdr_(v) = nc;
+			car_(v) = TAG_FWD;
+			cdr_(v) = nc;
 			car_(nc) = relocate(a);
 			pcdr = &cdr_(nc);
 			v = d;
--- a/llt/llt.h
+++ b/llt/llt.h
@@ -55,10 +55,8 @@
 
 #define LOG2_10 3.3219280948873626
 #define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
-#define sign_bit(r) ((*(uint64_t*)&(r)) & BIT63)
 #define LABS(n) (((n)^((n)>>(NBITS-1))) - ((n)>>(NBITS-1)))
 #define NBABS(n, nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
-#define DFINITE(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL) != 0x7ff0000000000000ULL)
 #define LLT_ALIGN(x, sz) (((x) + (sz-1)) & (-sz))
 
 // a mask with n set lo or hi bits
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -33,6 +33,8 @@
 #define asinf asin
 #define acosf acos
 #define atanf atan
+#define signbit(r) ((*(uint64_t*)&(r)) & BIT63)
+#define isfinite(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL) != 0x7ff0000000000000ULL)
 
 #define LC_NUMERIC 0
 #define setlocale(x, y)
--- a/print.c
+++ b/print.c
@@ -570,10 +570,7 @@
 		keepz = 1;
 	}
 	if(isnan(r)){
-		if(sign_bit(r))
-			strncpy(s, "-nan", cnt);
-		else
-			strncpy(s, "nan", cnt);
+		strncpy(s, signbit(r) ? "-nan" : "nan", cnt);
 		return;
 	}
 	if(r == 0){
@@ -683,12 +680,12 @@
 			d = *(double*)data;
 			ndec = 16;
 		}
-		if(!DFINITE(d)){
+		if(!isfinite(d)){
 			char *rep;
 			if(isnan(d))
-				rep = sign_bit(d) ? "-nan.0" : "+nan.0";
+				rep = signbit(d) ? "-nan.0" : "+nan.0";
 			else
-				rep = sign_bit(d) ? "-inf.0" : "+inf.0";
+				rep = signbit(d) ? "-inf.0" : "+inf.0";
 			if(type == floatsym && !print_princ && !weak)
 				HPOS += ios_printf(f, "#%s(%s)", symbol_name(type), rep);
 			else