From 9d98662882739be9869e2b3b403ead1a5ed131b6 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 10 May 2009 23:59:10 +0000 Subject: * ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support coercing into Rational. [ruby-core:23415] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 0abc00ab6..2f4b9ada3 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; } -- cgit