summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index cd960f4b87..571bf41461 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -675,12 +675,21 @@ BigDecimal_coerce(VALUE self, VALUE other)
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));
+ }
+ else {
+ if (TYPE(other) == T_RATIONAL) {
+ Real* pv = DATA_PTR(self);
+ GUARD_OBJ(b, GetVpValueWithPrec(other, pv->Prec*VpBaseFig(), 1));
+ }
+ else {
+ GUARD_OBJ(b, GetVpValue(other, 1));
+ }
obj = rb_assoc_new(b->obj, self);
}
+
return obj;
}