aboutsummaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'time.c')
-rw-r--r--time.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/time.c b/time.c
index e67a7bc5f7..bc2e769491 100644
--- a/time.c
+++ b/time.c
@@ -106,17 +106,51 @@ rb_localtime(const time_t *tm, struct tm *result)
static ID id_divmod, id_mul, id_submicro, id_subnano;
static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift;
-#define eq(x,y) (rb_funcall((x), id_eq, 1, (y)))
-#define ne(x,y) (rb_funcall((x), id_ne, 1, (y)))
+#define eq(x,y) (RTEST(rb_funcall((x), id_eq, 1, (y))))
+#define ne(x,y) (RTEST(rb_funcall((x), id_ne, 1, (y))))
#define lt(x,y) (RTEST(rb_funcall((x), '<', 1, (y))))
#define gt(x,y) (RTEST(rb_funcall((x), '>', 1, (y))))
#define le(x,y) (!gt(x,y))
#define ge(x,y) (!lt(x,y))
-#define add(x,y) (rb_funcall((x), '+', 1, (y)))
-#define sub(x,y) (rb_funcall((x), '-', 1, (y)))
-#define mul(x,y) (rb_funcall((x), '*', 1, (y)))
+
+static VALUE
+add(VALUE x, VALUE y)
+{
+ switch (TYPE(x)) {
+ case T_BIGNUM: return rb_big_plus(x, y);
+ default: return rb_funcall(x, '+', 1, y);
+ }
+}
+
+static VALUE
+sub(VALUE x, VALUE y)
+{
+ switch (TYPE(x)) {
+ case T_BIGNUM: return rb_big_minus(x, y);
+ default: return rb_funcall(x, '-', 1, y);
+ }
+}
+
+static VALUE
+mul(VALUE x, VALUE y)
+{
+ switch (TYPE(x)) {
+ case T_BIGNUM: return rb_big_mul(x, y);
+ default: return rb_funcall(x, '*', 1, y);
+ }
+}
+
#define div(x,y) (rb_funcall((x), id_div, 1, (y)))
-#define mod(x,y) (rb_funcall((x), '%', 1, (y)))
+
+static VALUE
+mod(VALUE x, VALUE y)
+{
+ switch (TYPE(x)) {
+ case T_BIGNUM: return rb_big_modulo(x, y);
+ default: return rb_funcall(x, '%', 1, y);
+ }
+}
+
#define neg(x) (sub(INT2FIX(0), (x)))
#define cmp(x,y) (rb_funcall((x), id_cmp, 1, (y)))
#define lshift(x,y) (rb_funcall((x), id_lshift, 1, (y)))