mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
1e3ca9807b
commit
3184ac2dfe
3 changed files with 18 additions and 2 deletions
|
@ -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
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue