From 35f851bcfe7e42ddf1b44606d2df4d4be9de9976 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 18 Dec 2001 08:47:06 +0000 Subject: * string.c (rb_str_replace): swap arguments of OBJ_INFECT. * eval.c (rb_thread_schedule): should not select a thread which is not yet initialized. * time.c (time_plus): wrong boundary check. * time.c (time_minus): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- time.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'time.c') diff --git a/time.c b/time.c index 4d8114b5c0..19ee8c1656 100644 --- a/time.c +++ b/time.c @@ -174,7 +174,7 @@ time_s_at(argc, argv, klass) if (rb_scan_args(argc, argv, "11", &time, &t) == 2) { tv.tv_sec = NUM2LONG(time); - tv.tv_usec = NUM2INT(t); + tv.tv_usec = NUM2LONG(t); } else { tv = rb_time_timeval(time); @@ -925,7 +925,7 @@ time_plus(time1, time2) { struct time_object *tobj; time_t sec, usec; - double f; + double f, d; GetTimeval(time1, tobj); @@ -934,10 +934,11 @@ time_plus(time1, time2) } f = NUM2DBL(time2); sec = (time_t)f; - if (f != (double)sec) { + d = f - (double)sec; + if (d >= 1.0 || d <= -1.0) { rb_raise(rb_eRangeError, "time + %f out of Time range", f); } - usec = tobj->tv.tv_usec + (time_t)((f - (double)sec)*1e6); + usec = tobj->tv.tv_usec + (time_t)(d*1e6); sec = tobj->tv.tv_sec + sec; #ifdef NEGATIVE_TIME_T @@ -960,7 +961,7 @@ time_minus(time1, time2) { struct time_object *tobj; time_t sec, usec; - double f; + double f, d; GetTimeval(time1, tobj); if (rb_obj_is_kind_of(time2, rb_cTime)) { @@ -974,10 +975,11 @@ time_minus(time1, time2) } f = NUM2DBL(time2); sec = (time_t)f; - if (f != (double)sec) { + d = f - (double)sec; + if (d >= 1.0 || d <= -1.0) { rb_raise(rb_eRangeError, "time - %f out of Time range", f); } - usec = tobj->tv.tv_usec - (time_t)((f - (double)sec)*1e6); + usec = tobj->tv.tv_usec - (time_t)(d*1e6); sec = tobj->tv.tv_sec - sec; #ifdef NEGATIVE_TIME_T if ((tobj->tv.tv_sec <= 0 && f >= 0 && sec > 0) || -- cgit v1.2.3