* time.c (time_minus): fix Time.at(2**60+1) - Time.at(2**60).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-11-18 09:30:17 +00:00
Родитель 1e3ca9807b
Коммит 3184ac2dfe
3 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Sun Nov 18 18:27:47 2007 Tanaka Akira <akr@fsij.org>
* time.c (time_minus): fix Time.at(2**60+1) - Time.at(2**60).
Sun Nov 18 17:28:49 2007 Tanaka Akira <akr@fsij.org>
* time.c (time_arg): show actual year in 2-3 digits year warning.

Просмотреть файл

@ -71,4 +71,14 @@ class TestTime < Test::Unit::TestCase
assert_equal(Time.at(0x7fffffff), Time.at(-0x80000000) - (-0xffffffff))
end
end
def test_big_minus
begin
bigtime0 = Time.at(2**60)
bigtime1 = Time.at(2**60+1)
rescue RangeError
return
end
assert_equal(1.0, bigtime1 - bigtime0)
end
end

6
time.c
Просмотреть файл

@ -1320,9 +1320,11 @@ time_minus(VALUE time1, VALUE time2)
double f;
GetTimeval(time2, tobj2);
f = (double)tobj->tv.tv_sec - (double)tobj2->tv.tv_sec;
if (tobj->tv.tv_sec < tobj2->tv.tv_sec)
f = -(double)(unsigned_time_t)(tobj2->tv.tv_sec - tobj->tv.tv_sec);
else
f = (double)(unsigned_time_t)(tobj->tv.tv_sec - tobj2->tv.tv_sec);
f += ((double)tobj->tv.tv_usec - (double)tobj2->tv.tv_usec)*1e-6;
/* XXX: should check float overflow on 64bit time_t platforms */
return DOUBLE2NUM(f);
}