diff --git a/src/structures/Constants.sac b/src/structures/Constants.sac index 9c523f2d..062f4263 100644 --- a/src/structures/Constants.sac +++ b/src/structures/Constants.sac @@ -111,7 +111,3 @@ external double maxdouble(); external double epidouble(); #pragma linksign[0] #pragma linkobj "src/Constants/epidouble.o" - -external int randmax(); - #pragma linksign[0] - #pragma linkobj "src/Constants/randmax.o" diff --git a/src/structures/src/Char/ctype.c b/src/structures/src/Char/ctype.c index 23c76850..301e5ae3 100644 --- a/src/structures/src/Char/ctype.c +++ b/src/structures/src/Char/ctype.c @@ -9,6 +9,7 @@ * They may return any non-zero value when true, but a SAC bool is true if 1. */ +#include #include typedef unsigned char uchar; @@ -68,12 +69,12 @@ int SACiscntrl(uchar c) return iscntrl(c) != 0; } -int SACisascii(int c) +int SACisascii(sac_int c) { return c >= 0 && c < 256 && isascii(c) != 0; } -int SACtoascii(int c) +int SACtoascii(sac_int c) { return toascii(c & 0xFF); } diff --git a/src/structures/src/Constants/maxint.c b/src/structures/src/Constants/maxint.c index 2078a486..f5080f5a 100644 --- a/src/structures/src/Constants/maxint.c +++ b/src/structures/src/Constants/maxint.c @@ -1,7 +1,15 @@ -#include +#include +#include -int maxint( void) +sac_int maxint( void) { - return( INT_MAX); + sac_int num_bits = 8 * sizeof(sac_int); + /** + * To avoid overflow: + * 2^(num_bits - 1) - 1 = 2 * 2^(num_bits - 2) - 1 = + * 2^(num_bits - 2) + (2^(num_bits - 2) - 1) + **/ + sac_int half = (sac_int)1 << (num_bits - 2); + return half + (half - 1); } diff --git a/src/structures/src/Constants/minint.c b/src/structures/src/Constants/minint.c index d369f318..b5127486 100644 --- a/src/structures/src/Constants/minint.c +++ b/src/structures/src/Constants/minint.c @@ -1,7 +1,8 @@ +#include #include - -int minint( void) +sac_int minint( void) { - return( INT_MIN ); + sac_int num_bits = 8 * sizeof(sac_int); + return -((sac_int)1 << (num_bits - 1)); }