Skip to content

Commit

Permalink
Stop using GetVpValueWithPrec in rb_float_convert_to_BigDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Jan 9, 2021
1 parent 28d3836 commit 33e7c50
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2806,10 +2806,13 @@ rb_inum_convert_to_BigDecimal(VALUE val, RB_UNUSED_VAR(size_t digs), int raise_e
}
}

static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception);

static VALUE
rb_float_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
{
double d = RFLOAT_VALUE(val);

if (!isfinite(d)) {
Real *vp = VpCreateRbObject(1, NULL, true); /* vp->obj is allocated */
VpDtoV(vp, d);
Expand All @@ -2829,7 +2832,18 @@ rb_float_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
rb_raise(rb_eArgError, "precision too large.");
}

Real *vp = GetVpValueWithPrec(val, digs, 1);
if (d != 0.0) {
val = rb_funcall(val, id_to_r, 0);
return rb_rational_convert_to_BigDecimal(val, digs, raise_exception);
}

Real *vp;
if (1/d < 0.0) {
vp = VpCreateRbObject(digs, "-0", true);
}
else {
vp = VpCreateRbObject(digs, "0", true);
}
return check_exception(vp->obj);
}

Expand Down

0 comments on commit 33e7c50

Please sign in to comment.