aboutsummaryrefslogtreecommitdiffstats
path: root/ext/bigdecimal/bigdecimal.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r--ext/bigdecimal/bigdecimal.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 0abc00ab61..2f4b9ada34 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -675,11 +675,16 @@ 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));
- 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;
}