summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
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;