mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
92fd1940fe
commit
d9bfa822ea
3 changed files with 24 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Sep 22 04:47:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/bigdecimal/bigdecimal.c (GetVpValue): support conversion from
|
||||||
|
Rational. [ruby-core:25697]
|
||||||
|
|
||||||
Tue Sep 22 04:43:42 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Sep 22 04:43:42 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* Makefile.in, win32/Makefile.sub (INSNS): depend on tools.
|
* Makefile.in, win32/Makefile.sub (INSNS): depend on tools.
|
||||||
|
|
|
@ -239,9 +239,24 @@ GetVpValue(VALUE v, int must)
|
||||||
Real *pv;
|
Real *pv;
|
||||||
VALUE bg;
|
VALUE bg;
|
||||||
char szD[128];
|
char szD[128];
|
||||||
|
VALUE orig = Qundef;
|
||||||
|
int util_loaded = 0;
|
||||||
|
|
||||||
|
again:
|
||||||
switch(TYPE(v))
|
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:
|
case T_DATA:
|
||||||
if(rb_typeddata_is_kind_of(v, &BigDecimal_data_type)) {
|
if(rb_typeddata_is_kind_of(v, &BigDecimal_data_type)) {
|
||||||
pv = DATA_PTR(v);
|
pv = DATA_PTR(v);
|
||||||
|
|
|
@ -691,4 +691,8 @@ class TestBigDecimal < Test::Unit::TestCase
|
||||||
assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("1E-1" + "0" * 10000).sign)
|
assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("1E-1" + "0" * 10000).sign)
|
||||||
assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign)
|
assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_coerce
|
||||||
|
assert_equal(2, 1 + BigDecimal.new("1"), '[ruby-core:25697]')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue