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

ruby-changes:64889

From: Kenta <ko1@a...>
Date: Fri, 15 Jan 2021 06:49:33 +0900 (JST)
Subject: [ruby-changes:64889] 0a039c5fbb (master): [ruby/bigdecimal] Use new conversion functions in BigDecimal_divide

https://git.ruby-lang.org/ruby.git/commit/?id=0a039c5fbb

From 0a039c5fbb247364961e0471582024751bc2be53 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Fri, 15 Jan 2021 06:19:39 +0900
Subject: [ruby/bigdecimal] Use new conversion functions in BigDecimal_divide

https://github.com/ruby/bigdecimal/commit/3b55ad1c42

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index a3df2e5..2191007 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -209,6 +209,7 @@ static VALUE rb_inum_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exc https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L209
 static VALUE rb_float_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception);
 static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception);
 static VALUE rb_cstr_convert_to_BigDecimal(const char *c_str, size_t digs, int raise_exception);
+static VALUE rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception);
 
 static Real*
 GetVpValueWithPrec(VALUE v, long prec, int must)
@@ -1352,18 +1353,25 @@ BigDecimal_divide(VALUE self, VALUE r, Real **c, Real **res, Real **div) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1353
     Real *a, *b;
     size_t mx;
 
-    GUARD_OBJ(a, GetVpValue(self, 1));
+    TypedData_Get_Struct(self, Real, &BigDecimal_data_type, a);
+    SAVE(a);
+
+    VALUE rr = Qnil;
     if (RB_TYPE_P(r, T_FLOAT)) {
-        b = GetVpValueWithPrec(r, 0, 1);
+        rr = rb_float_convert_to_BigDecimal(r, 0, true);
     }
     else if (RB_TYPE_P(r, T_RATIONAL)) {
-	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
-     }
+        rr = rb_rational_convert_to_BigDecimal(r, a->Prec*BASE_FIG, true);
+    }
     else {
-	b = GetVpValue(r, 0);
+        rr = rb_convert_to_BigDecimal(r, 0, false);
+    }
+
+    if (!is_kind_of_BigDecimal(rr)) {
+        return DoSomeOne(self, r, '/');
     }
 
-    if (!b) return DoSomeOne(self, r, '/');
+    TypedData_Get_Struct(rr, Real, &BigDecimal_data_type, b);
     SAVE(b);
 
     *div = b;
-- 
cgit v0.10.2


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

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