summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-01-15 10:44:45 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-01-16 00:09:26 +0900
commitb1306445842eee53e23fd932a85d252d183e63b5 (patch)
tree276ba3b2b44bfc6c4a25b0d19f4478dbf98e99ac /ext/bigdecimal
parent9d0c5e2754c72936d604405152aebc149675a2e6 (diff)
[ruby/bigdecimal] Fix for the coerce cases in divide and DoDivmod
https://github.com/ruby/bigdecimal/commit/1cb92487f7
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 8c79450..bcc2b32 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -1356,16 +1356,19 @@ BigDecimal_divide(VALUE self, VALUE r, Real **c, Real **res, Real **div)
TypedData_Get_Struct(self, Real, &BigDecimal_data_type, a);
SAVE(a);
- VALUE rr = Qnil;
- if (RB_TYPE_P(r, T_FLOAT)) {
+ VALUE rr = r;
+ if (is_kind_of_BigDecimal(rr)) {
+ /* do nothing */
+ }
+ else if (RB_INTEGER_TYPE_P(r)) {
+ rr = rb_inum_convert_to_BigDecimal(r, 0, true);
+ }
+ else if (RB_TYPE_P(r, T_FLOAT)) {
rr = rb_float_convert_to_BigDecimal(r, 0, true);
}
else if (RB_TYPE_P(r, T_RATIONAL)) {
rr = rb_rational_convert_to_BigDecimal(r, a->Prec*BASE_FIG, true);
}
- else {
- rr = rb_convert_to_BigDecimal(r, 0, false);
- }
if (!is_kind_of_BigDecimal(rr)) {
return DoSomeOne(self, r, '/');
@@ -1429,16 +1432,19 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
TypedData_Get_Struct(self, Real, &BigDecimal_data_type, a);
SAVE(a);
- VALUE rr = Qnil;
- if (RB_TYPE_P(r, T_FLOAT)) {
+ VALUE rr = r;
+ if (is_kind_of_BigDecimal(rr)) {
+ /* do nothing */
+ }
+ else if (RB_INTEGER_TYPE_P(r)) {
+ rr = rb_inum_convert_to_BigDecimal(r, 0, true);
+ }
+ else if (RB_TYPE_P(r, T_FLOAT)) {
rr = rb_float_convert_to_BigDecimal(r, 0, true);
}
else if (RB_TYPE_P(r, T_RATIONAL)) {
rr = rb_rational_convert_to_BigDecimal(r, a->Prec*BASE_FIG, true);
}
- else {
- rr = rb_convert_to_BigDecimal(r, 0, false);
- }
if (!is_kind_of_BigDecimal(rr)) {
return Qfalse;