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

ruby-changes:12240

From: akr <ko1@a...>
Date: Thu, 2 Jul 2009 05:18:55 +0900 (JST)
Subject: [ruby-changes:12240] Ruby:r23928 (trunk): * time.c (quo): return an integer if possible.

akr	2009-07-02 05:17:00 +0900 (Thu, 02 Jul 2009)

  New Revision: 23928

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

  Log:
    * time.c (quo): return an integer if possible.

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 23927)
+++ time.c	(revision 23928)
@@ -112,13 +112,24 @@
 #define add(x,y) (rb_funcall((x), '+', 1, (y)))
 #define sub(x,y) (rb_funcall((x), '-', 1, (y)))
 #define mul(x,y) (rb_funcall((x), '*', 1, (y)))
-#define quo(x,y) (rb_funcall((x), id_quo, 1, (y)))
 #define div(x,y) (rb_funcall((x), id_div, 1, (y)))
 #define mod(x,y) (rb_funcall((x), '%', 1, (y)))
 #define neg(x) (sub(INT2FIX(0), (x)))
 #define cmp(x,y) (rb_funcall((x), id_cmp, 1, (y)))
 #define lshift(x,y) (rb_funcall((x), id_lshift, 1, (y)))
 
+static VALUE
+quo(VALUE x, VALUE y)
+{
+    VALUE ret;
+    ret = rb_funcall((x), id_quo, 1, (y));
+    if (TYPE(ret) == T_RATIONAL &&
+        ((struct RRational *)ret)->den == INT2FIX(1)) {
+        ret = ((struct RRational *)ret)->num;
+    }
+    return ret;
+}
+
 static void
 divmodv(VALUE n, VALUE d, VALUE *q, VALUE *r)
 {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23927)
+++ ChangeLog	(revision 23928)
@@ -1,3 +1,7 @@
+Thu Jul  2 05:15:54 2009  Tanaka Akira  <akr@f...>
+
+	* time.c (quo): return an integer if possible.
+
 Wed Jul  1 21:09:25 2009  Tanaka Akira  <akr@f...>
 
 	* include/ruby/intern.h (rb_time_num_new): declared.

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

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