summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-27 06:52:17 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-27 06:52:17 +0000
commitd907adecd9267d6cddb77d1fd7c4c6fcb878772e (patch)
tree1254eac16c20dd41196f38825e88e394e80ea501 /internal.h
parente88a692a884a2c9d5349e1e94da3b0d77247adc2 (diff)
* 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
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h15
1 files changed, 11 insertions, 4 deletions
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))