From d907adecd9267d6cddb77d1fd7c4c6fcb878772e Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 27 Apr 2013 06:52:17 +0000 Subject: * internal.h (SIGNED_INTEGER_TYPE_P): New macro. (SIGNED_INTEGER_MAX): Ditto. (SIGNED_INTEGER_MIN): Ditto. (UNSIGNED_INTEGER_MAX): Ditto. (TIMET_MAX): Use SIGNED_INTEGER_MAX and UNSIGNED_INTEGER_MAX. (TIMET_MIN): Use SIGNED_INTEGER_MIN. * thread.c (TIMEVAL_SEC_MAX): Use SIGNED_INTEGER_MAX. (TIMEVAL_SEC_MIN): Use SIGNED_INTEGER_MIN. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- internal.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'internal.h') diff --git a/internal.h b/internal.h index 90388533dc..7044efe5df 100644 --- a/internal.h +++ b/internal.h @@ -25,12 +25,19 @@ extern "C" { (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) +#define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1) +#define SIGNED_INTEGER_MAX(sint_type) \ + ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \ + ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1)) +#define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1) +#define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0) + #if SIGNEDNESS_OF_TIME_T < 0 /* signed */ -# define TIMET_MAX (time_t)((~(unsigned_time_t)0) >> 1) -# define TIMET_MIN (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) +# define TIMET_MAX SIGNED_INTEGER_MAX(time_t) +# define TIMET_MIN SIGNED_INTEGER_MIN(time_t) #elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */ -# define TIMET_MAX (time_t)(~(unsigned_time_t)0) -# define TIMET_MIN (time_t)0 +# define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t) +# define TIMET_MIN ((time_t)0) #endif #define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1)) -- cgit v1.2.3