1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* time.c: fix rounding negative float.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-06-27 16:10:46 +00:00
parent e509574dea
commit 6e90749f80
3 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat Jun 28 01:08:42 2008 Tanaka Akira <akr@fsij.org>
* time.c (time_timespec): fix rounding negative float.
Fri Jun 27 21:38:57 2008 Tanaka Akira <akr@fsij.org>
* struct.c: __size__ removed. use the length of __members__ instead.

View file

@ -105,6 +105,18 @@ class TestTime < Test::Unit::TestCase
assert_equal(100, Time.at(0.0000001).nsec)
assert_equal(10, Time.at(0.00000001).nsec)
assert_equal(1, Time.at(0.000000001).nsec)
assert_equal(0, Time.at(1e-10).nsec)
assert_equal(0, Time.at(4e-10).nsec)
assert_equal(1, Time.at(6e-10).nsec)
assert_equal(1, Time.at(14e-10).nsec)
assert_equal(2, Time.at(16e-10).nsec)
if negative_time_t?
assert_equal(0, Time.at(-1e-10).nsec)
assert_equal(0, Time.at(-4e-10).nsec)
assert_equal(999999999, Time.at(-6e-10).nsec)
assert_equal(999999999, Time.at(-14e-10).nsec)
assert_equal(999999998, Time.at(-16e-10).nsec)
end
end
def test_at2

4
time.c
View file

@ -201,6 +201,10 @@ time_timespec(VALUE num, int interval)
double f, d;
d = modf(RFLOAT_VALUE(num), &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_VALUE(num));