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

ruby-changes:11743

From: matz <ko1@a...>
Date: Mon, 11 May 2009 09:02:50 +0900 (JST)
Subject: [ruby-changes:11743] Ruby:r23389 (trunk): * ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support

matz	2009-05-11 08:59:10 +0900 (Mon, 11 May 2009)

  New Revision: 23389

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

  Log:
    * ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support
       coercing into Rational.   [ruby-core:23415]

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23388)
+++ ChangeLog	(revision 23389)
@@ -1,3 +1,8 @@
+Mon May 11 08:37:04 2009  Yukihiro Matsumoto  <matz@r...>
+
+	* ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support
+	   coercing into Rational.   [ruby-core:23415]
+
 Mon May 11 04:39:45 2009  Yukihiro Matsumoto  <matz@r...>
 
 	* lib/net/smtp.rb (Net::SMTP#check_auth_args): should not change
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 23388)
+++ ext/bigdecimal/bigdecimal.c	(revision 23389)
@@ -675,11 +675,16 @@
     ENTER(2);
     VALUE obj;
     Real *b;
-    if(TYPE(other) == T_FLOAT) {
-       obj = rb_assoc_new(other, BigDecimal_to_f(self));
-    } else {
-       GUARD_OBJ(b,GetVpValue(other,1));
-       obj = rb_assoc_new(b->obj, self);
+    switch (TYPE(other)) {
+      case T_FLOAT:
+	obj = rb_assoc_new(other, BigDecimal_to_f(self));
+	break;
+      case T_RATIONAL:
+	obj = rb_assoc_new(other, BigDecimal_to_r(self));
+	break;
+      default:
+	GUARD_OBJ(b,GetVpValue(other,1));
+	obj = rb_assoc_new(b->obj, self);
     }
     return obj;
 }

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

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