summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 16:42:27 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 16:42:27 +0000
commit4fffacd9a51227cf043873d5ac3e961a2ed0a2f5 (patch)
tree915c60a34658fbee84299f87724fe7c932299c8b /time.c
parent7adb8681f015fd958288edd9c5d78484764ec34a (diff)
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
Diffstat (limited to 'time.c')
-rw-r--r--time.c12
1 files changed, 7 insertions, 5 deletions
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;