shithub: femtolisp

Download patch

ref: a4555311d608affb0ac44197efd6fbde2617b433
parent: b1573af3e04e04b2046eb0d2ef9dd92727b16ea6
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Mar 14 15:03:58 EDT 2023

(U)INT_{MIN,MAX} -> (U)INT32_{MIN,MAX}

--- a/cvalues.c
+++ b/cvalues.c
@@ -1016,10 +1016,10 @@
     if (Uaccum > (uint64_t)INT64_MAX) {
         RETURN_NUM_AS(Uaccum, uint64);
     }
-    else if (Uaccum > (uint64_t)UINT_MAX) {
+    else if (Uaccum > (uint64_t)UINT32_MAX) {
         RETURN_NUM_AS(Uaccum, int64);
     }
-    else if (Uaccum > (uint64_t)INT_MAX) {
+    else if (Uaccum > (uint64_t)INT32_MAX) {
         RETURN_NUM_AS(Uaccum, uint32);
     }
     RETURN_NUM_AS(Uaccum, int32);
@@ -1030,10 +1030,10 @@
     if (fits_fixnum(Saccum)) {
         return fixnum((fixnum_t)Saccum);
     }
-    if (Saccum > (int64_t)UINT_MAX || Saccum < (int64_t)INT_MIN) {
+    if (Saccum > (int64_t)UINT32_MAX || Saccum < (int64_t)INT32_MIN) {
         RETURN_NUM_AS(Saccum, int64);
     }
-    else if (Saccum > (int64_t)INT_MAX) {
+    else if (Saccum > (int64_t)INT32_MAX) {
         RETURN_NUM_AS(Saccum, uint32);
     }
     RETURN_NUM_AS(Saccum, int32);
@@ -1092,7 +1092,7 @@
         if (negpart > Uaccum) {
             Saccum += (int64_t)Uaccum;
             // return value in Saccum
-            if (Saccum >= INT_MIN) {
+            if (Saccum >= INT32_MIN) {
                 if (fits_fixnum(Saccum)) {
                     return fixnum((fixnum_t)Saccum);
                 }
@@ -1136,7 +1136,7 @@
             return mk_int32(-i32);
         case T_UINT32:
             ui32 = *(uint32_t*)a;
-            if (ui32 <= ((uint32_t)INT_MAX)+1) return mk_int32(-(int32_t)ui32);
+            if (ui32 <= ((uint32_t)INT32_MAX)+1) return mk_int32(-(int32_t)ui32);
             return mk_int64(-(int64_t)ui32);
         case T_INT64:
             i64 = *(int64_t*)a;
@@ -1202,7 +1202,7 @@
     }
     else if (Saccum < 0) {
         Saccum *= (int64_t)Uaccum;
-        if (Saccum >= INT_MIN) {
+        if (Saccum >= INT32_MIN) {
             if (fits_fixnum(Saccum)) {
                 return fixnum((fixnum_t)Saccum);
             }
--- a/llt/llt.h
+++ b/llt/llt.h
@@ -30,14 +30,14 @@
 
 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
 #define bswap_32(x) \
-    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
-    (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
+    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
+    (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
 #define bswap_64(x) \
     (uint64_t)bswap_32((x) & 0xffffffffULL)<<32 | \
     (uint64_t)bswap_32(((x)>>32) & 0xffffffffULL)
 
-#define DBL_MAXINT 9007199254740992LL
-#define FLT_MAXINT 16777216
+#define DBL_MAXINT (1LL<<53)
+#define FLT_MAXINT (1<<24)
 #define BIT63 0x8000000000000000ULL
 #define BIT31 0x80000000UL
 
--- a/operators.c
+++ b/operators.c
@@ -21,7 +21,7 @@
     fp = fpart(r);
     if (fp != 0 || r > (double)INT64_MAX || r < INT64_MIN)
         return T_DOUBLE;
-    else if (r >= INT_MIN && r <= INT_MAX)
+    else if (r >= INT32_MIN && r <= INT32_MAX)
         return T_INT32;
     else if (r <= (double)INT64_MAX)
         return T_INT64;
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -46,9 +46,9 @@
 #endif
 
 #define NULL nil
-#define INT_MAX 0x7fffffff
-#define UINT_MAX 0xffffffffU
-#define INT_MIN (-INT_MAX-1)
+#define INT32_MAX 0x7fffffff
+#define UINT32_MAX 0xffffffffU
+#define INT32_MIN (-INT32_MAX-1)
 #define INT64_MIN ((int64_t)0x8000000000000000LL)
 #define INT64_MAX 0x7fffffffffffffffLL
 #define UINT64_MAX 0xffffffffffffffffULL
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -60,7 +60,7 @@
 (assert (not (eqv? 10 #\newline)))
 (assert (not (eqv? #\newline 10)))
 
-; tricky cases involving INT_MIN
+; tricky cases involving INT32_MIN
 (assert (< (- #uint32(0x80000000)) 0))
 (assert (> (- #int32(0x80000000)) 0))
 (assert (< (- #uint64(0x8000000000000000)) 0))