summaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 16:18:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 16:18:18 +0000
commitbd50695d20ecdda4c42f8d21b93dc1211a94e044 (patch)
treefaf4ce630628b63cf47436b1f037124774c1dc6e /time.c
parent0b45bb82b01241d40e8e6d2a613f1b0095fa9c34 (diff)
downloadruby-bd50695d20ecdda4c42f8d21b93dc1211a94e044.tar.gz
ruby-bd50695d20ecdda4c42f8d21b93dc1211a94e044.tar.xz
ruby-bd50695d20ecdda4c42f8d21b93dc1211a94e044.zip
* time.c (time_timespec): rounds subsecond toward zero.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/time.c b/time.c
index d349009dc..74f1f2855 100644
--- a/time.c
+++ b/time.c
@@ -1499,22 +1499,17 @@ time_timespec(VALUE num, int interval)
double f, d;
d = modf(RFLOAT_VALUE(num), &f);
- if (d < 0) {
- d += 1;
- f -= 1;
- }
+ if (d >= 0) {
+ t.tv_nsec = (int)(d*1e9+0.5);
+ }
+ else if ((t.tv_nsec = (int)(-d*1e9+0.5)) > 0) {
+ t.tv_nsec = 1000000000 - t.tv_nsec;
+ f -= 1;
+ }
t.tv_sec = (time_t)f;
if (f != t.tv_sec) {
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
}
- t.tv_nsec = (int)(d*1e9+0.5);
- if (t.tv_nsec >= 1000000000) {
- t.tv_nsec -= 1000000000;
- if (++t.tv_sec <= 0) {
- --t.tv_nsec;
- t.tv_nsec = 999999999;
- }
- }
}
break;