summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-21 19:47:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-21 19:47:39 +0000
commit0be854292dc0ca99fc9972ca88f9bf4954c9fcf0 (patch)
tree8bd66f5787510e1ee4d108621901dbbf4d6d03db /ext
parentc5a1c17148bb4916fd71bba369c158d0cdd76ac0 (diff)
downloadruby-0be854292dc0ca99fc9972ca88f9bf4954c9fcf0.tar.gz
ruby-0be854292dc0ca99fc9972ca88f9bf4954c9fcf0.tar.xz
ruby-0be854292dc0ca99fc9972ca88f9bf4954c9fcf0.zip
* ext/bigdecimal/bigdecimal.c (GetVpValue): support conversion from
Rational. [ruby-core:25697] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 97d1822e0..4e60bae17 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -239,9 +239,24 @@ GetVpValue(VALUE v, int must)
Real *pv;
VALUE bg;
char szD[128];
+ VALUE orig = Qundef;
+ int util_loaded = 0;
+again:
switch(TYPE(v))
{
+ case T_RATIONAL:
+ if(orig == Qundef ? (orig = v, 1) : orig != v) {
+ if(!util_loaded) {
+ rb_require("bigdecimal/util");
+ util_loaded = 1;
+ }
+ v = rb_funcall2(v, rb_intern("to_d"), 0, 0);
+ goto again;
+ }
+ v = orig;
+ goto SomeOneMayDoIt;
+
case T_DATA:
if(rb_typeddata_is_kind_of(v, &BigDecimal_data_type)) {
pv = DATA_PTR(v);