diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-12 16:18:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-12 16:18:51 +0000 |
commit | 4e94c36f3d46cee252ba431b2c8db0b4a211b374 (patch) | |
tree | 700f1ec428f1ac2b782a19425ca716d252641c36 /time.c | |
parent | 703bff0b24a10916ff5f59f9bb1684aa1e3ecca1 (diff) |
* time.c (time_timeval): rounds subsecond toward zero.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -192,22 +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 = (int)(d*1e6+0.5); - if (t.tv_usec >= 1000000) { - t.tv_usec -= 1000000; - if (++t.tv_sec <= 0) { - --t.tv_sec; - t.tv_usec = 999999; - } - } } break; |