From 4fffacd9a51227cf043873d5ac3e961a2ed0a2f5 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Sun, 12 Jul 2009 16:42:27 +0000 Subject: merge revision(s) 23259,24059: * time.c (time_timeval): check out-of-range. [ruby-core:23282] [Bug #1396] * time.c (time_timeval): rounds subsecond toward zero. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@24060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- time.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'time.c') diff --git a/time.c b/time.c index fb1ab30821..5cd1c9ed3a 100644 --- a/time.c +++ b/time.c @@ -192,15 +192,17 @@ time_timeval(time, interval) double f, d; d = modf(RFLOAT(time)->value, &f); - if (d < 0) { - d += 1; - f -= 1; - } + if (d >= 0) { + t.tv_usec = (int)(d*1e6+0.5); + } + else if ((t.tv_usec = (int)(-d*1e6+0.5)) > 0) { + t.tv_usec = 1000000 - t.tv_usec; + f -= 1; + } t.tv_sec = (time_t)f; if (f != t.tv_sec) { rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT(time)->value); } - t.tv_usec = (time_t)(d*1e6+0.5); } break; -- cgit v1.2.3