From 3184ac2dfed8366246df87af97eee548f4ab7248 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 18 Nov 2007 09:30:17 +0000 Subject: [PATCH] * 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 --- ChangeLog | 4 ++++ test/ruby/test_time.rb | 10 ++++++++++ time.c | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fce7f4f9a3..0bd05ff231 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Nov 18 18:27:47 2007 Tanaka Akira + + * time.c (time_minus): fix Time.at(2**60+1) - Time.at(2**60). + Sun Nov 18 17:28:49 2007 Tanaka Akira * time.c (time_arg): show actual year in 2-3 digits year warning. diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 6177e198d9..db922e1177 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -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 diff --git a/time.c b/time.c index 7d09c289e7..dc71a93c07 100644 --- a/time.c +++ b/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); }