summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-29 11:09:30 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-29 11:09:30 +0000
commit7c1aaff1eb18c836c620096f0fc05e2f8fc629a3 (patch)
treed486658c67e730eb2cff35b162ac0716e6a7b294
parent5f664fd092369bbd4c13b826af58821f071d49f0 (diff)
merge revision(s) 17617:
* time.c (time_timeval): fix rounding negative float. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@17709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--test/ruby/test_time.rb21
-rw-r--r--time.c4
-rw-r--r--version.h2
4 files changed, 30 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 06000de..f1368bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jun 29 20:08:11 2008 Tanaka Akira <akr@fsij.org>
+
+ * time.c (time_timeval): fix rounding negative float.
+
Sun Jun 29 19:19:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/inlinetest.rb (InlineTest.in_progname): workaround for frozen
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index ad9b64a..ae1a35f 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -71,4 +71,25 @@ class TestTime < Test::Unit::TestCase
assert_equal(Time.at(0x7fffffff), Time.at(-0x80000000) - (-0xffffffff))
end
end
+
+ def test_at
+ assert_equal(100000, Time.at(0.1).usec)
+ assert_equal(10000, Time.at(0.01).usec)
+ assert_equal(1000, Time.at(0.001).usec)
+ assert_equal(100, Time.at(0.0001).usec)
+ assert_equal(10, Time.at(0.00001).usec)
+ assert_equal(1, Time.at(0.000001).usec)
+ assert_equal(0, Time.at(1e-7).usec)
+ assert_equal(0, Time.at(4e-7).usec)
+ assert_equal(1, Time.at(6e-7).usec)
+ assert_equal(1, Time.at(14e-7).usec)
+ assert_equal(2, Time.at(16e-7).usec)
+ if negative_time_t?
+ assert_equal(0, Time.at(-1e-7).usec)
+ assert_equal(0, Time.at(-4e-7).usec)
+ assert_equal(999999, Time.at(-6e-7).usec)
+ assert_equal(999999, Time.at(-14e-7).usec)
+ assert_equal(999998, Time.at(-16e-7).usec)
+ end
+ end
end
diff --git a/time.c b/time.c
index a5c2619..59e8721 100644
--- a/time.c
+++ b/time.c
@@ -192,6 +192,10 @@ time_timeval(time, interval)
double f, d;
d = modf(RFLOAT(time)->value, &f);
+ if (d < 0) {
+ d += 1;
+ 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);
diff --git a/version.h b/version.h
index fd530ae..e42ed38 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-29"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20080629
-#define RUBY_PATCHLEVEL 35
+#define RUBY_PATCHLEVEL 36
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8