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

ruby-changes:11835

From: mame <ko1@a...>
Date: Tue, 19 May 2009 23:00:19 +0900 (JST)
Subject: [ruby-changes:11835] Ruby:r23490 (trunk): * time.c (time_minus): always return a Float.

mame	2009-05-19 23:00:04 +0900 (Tue, 19 May 2009)

  New Revision: 23490

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23490

  Log:
    * time.c (time_minus): always return a Float.  [ruby-dev:38446]
    * time.c (time_to_r): new method.  [ruby-dev:38461]

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 23489)
+++ time.c	(revision 23490)
@@ -2277,6 +2277,30 @@
 
 /*
  *  call-seq:
+ *     time.to_r => Rational
+ *
+ *  Returns the value of <i>time</i> as a rational number of seconds
+ *  since the Epoch.
+ *
+ *     t = Time.now
+ *     p t.to_r            #=> (8807170717088293/8388608)
+ *
+ *  This methods is intended to be used to get an accurate value
+ *  representing nanoseconds from the Epoch.  You can use this
+ *  to convert time to another Epoch.
+ */
+
+static VALUE
+time_to_r(VALUE time)
+{
+    struct time_object *tobj;
+
+    GetTimeval(time, tobj);
+    return tobj->timev;
+}
+
+/*
+ *  call-seq:
  *     time.usec    => int
  *     time.tv_usec => int
  *
@@ -2803,7 +2827,7 @@
 	struct time_object *tobj2;
 
 	GetTimeval(time2, tobj2);
-        return sub(tobj->timev, tobj2->timev);
+        return rb_Float(sub(tobj->timev, tobj2->timev));
     }
     return time_add(tobj, time2, -1);
 }
@@ -3682,6 +3706,7 @@
 
     rb_define_method(rb_cTime, "to_i", time_to_i, 0);
     rb_define_method(rb_cTime, "to_f", time_to_f, 0);
+    rb_define_method(rb_cTime, "to_r", time_to_r, 0);
     rb_define_method(rb_cTime, "<=>", time_cmp, 1);
     rb_define_method(rb_cTime, "eql?", time_eql, 1);
     rb_define_method(rb_cTime, "hash", time_hash, 0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23489)
+++ ChangeLog	(revision 23490)
@@ -1,3 +1,9 @@
+Tue May 19 22:54:35 2009  Yusuke Endoh  <mame@t...>
+
+	* time.c (time_minus): always return a Float.  [ruby-dev:38446]
+
+	* time.c (time_to_r): new method.  [ruby-dev:38461]
+
 Tue May 19 13:59:35 2009  Yukihiro Matsumoto  <matz@r...>
 
 	* class.c (clone_method): add cast to remove warning from

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

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