diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-10 23:59:10 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-10 23:59:10 +0000 |
commit | 70abf7e8fa8d84987465b2f43c47264087cb54d6 (patch) | |
tree | d9acb921489af16566c18cb0c9322b87575678f9 /ext/bigdecimal | |
parent | 81cf906bbd9a073038a8ed7237dd8e8cade0534d (diff) |
* ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support
coercing into Rational. [ruby-core:23415]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 15 |
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; } |