From d9bfa822ea7e23dcc0dd1572773495419d89e145 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 21 Sep 2009 19:47:39 +0000 Subject: * ext/bigdecimal/bigdecimal.c (GetVpValue): support conversion from Rational. [ruby-core:25697] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/bigdecimal') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 97d1822e0d..4e60bae173 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); -- cgit v1.2.3