summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/bigdecimal/bigdecimal.c15
2 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index a4bb4ecf1..f6bec84f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon May 11 08:37:04 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/bigdecimal/bigdecimal.c (BigDecimal_coerce): support
+ coercing into Rational. [ruby-core:23415]
+
Mon May 11 04:39:45 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/net/smtp.rb (Net::SMTP#check_auth_args): should not change
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;
}