[前][次][番号順一覧][スレッド一覧]

ruby-changes:2469

From: ko1@a...
Date: 18 Nov 2007 18:30:28 +0900
Subject: [ruby-changes:2469] akr - Ruby:r13960 (trunk): * time.c (time_minus): fix Time.at(2**60+1) - Time.at(2**60).

akr	2007-11-18 18:30:17 +0900 (Sun, 18 Nov 2007)

  New Revision: 13960

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c

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


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/time.c?r1=13960&r2=13959
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13960&r2=13959
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_time.rb?r1=13960&r2=13959

Index: time.c
===================================================================
--- time.c	(revision 13959)
+++ time.c	(revision 13960)
@@ -1320,9 +1320,11 @@
 	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);
     }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13959)
+++ ChangeLog	(revision 13960)
@@ -1,3 +1,7 @@
+Sun Nov 18 18:27:47 2007  Tanaka Akira  <akr@f...>
+
+	* time.c (time_minus): fix Time.at(2**60+1) - Time.at(2**60).
+
 Sun Nov 18 17:28:49 2007  Tanaka Akira  <akr@f...>
 
 	* time.c (time_arg): show actual year in 2-3 digits year warning.
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 13959)
+++ test/ruby/test_time.rb	(revision 13960)
@@ -71,4 +71,14 @@
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]