зеркало из https://github.com/github/ruby.git
* ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons [ruby-core:26646]
* test/bigdecimal/test_bigdecimal.rb (class): Fix and improve tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d71eab14fb
Коммит
c07e7d167d
|
@ -1,3 +1,10 @@
|
|||
Sat Nov 14 09:16:54 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons
|
||||
[ruby-core:26646]
|
||||
|
||||
* test/bigdecimal/test_bigdecimal.rb (class): Fix and improve tests.
|
||||
|
||||
Sat Nov 14 04:07:06 2009 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||
|
||||
* ext/tk/lib/tk/variable.rb (TkVariable::coerce): fix bug on a
|
||||
|
|
|
@ -724,23 +724,21 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
|
|||
|
||||
switch(op)
|
||||
{
|
||||
case '*': f = rb_intern("<=>");break;
|
||||
case '=': f = rb_intern("=="); break;
|
||||
case '!': f = rb_intern("!="); break;
|
||||
case '*': return rb_num_coerce_cmp(self,r,rb_intern("<=>"));
|
||||
case '=': return RTEST(rb_num_coerce_cmp(self,r,rb_intern("=="))) ? Qtrue : Qfalse;
|
||||
case 'G': f = rb_intern(">="); break;
|
||||
case 'L': f = rb_intern("<="); break;
|
||||
case '>': case '<': f = (ID)op; break;
|
||||
}
|
||||
return rb_num_coerce_cmp(self,r,f);
|
||||
return rb_num_coerce_relop(self,r,f);
|
||||
}
|
||||
SAVE(b);
|
||||
e = VpComp(a, b);
|
||||
if(e==999) return Qnil;
|
||||
if(e==999) return (op == '*') ? Qnil : Qfalse;
|
||||
switch(op)
|
||||
{
|
||||
case '*': return INT2FIX(e); /* any op */
|
||||
case '=': if(e==0) return Qtrue ; return Qfalse;
|
||||
case '!': if(e!=0) return Qtrue ; return Qfalse;
|
||||
case 'G': if(e>=0) return Qtrue ; return Qfalse;
|
||||
case '>': if(e> 0) return Qtrue ; return Qfalse;
|
||||
case 'L': if(e<=0) return Qtrue ; return Qfalse;
|
||||
|
|
|
@ -61,7 +61,6 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||
x = BigDecimal.new("0.1")
|
||||
100.times do
|
||||
x *= x
|
||||
break if x == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,7 +70,6 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||
x = BigDecimal.new("10")
|
||||
100.times do
|
||||
x *= x
|
||||
break if x == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -219,7 +217,20 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||
assert_operator(1, :<, inf)
|
||||
end
|
||||
|
||||
def test_cmp_corece
|
||||
def test_cmp_nan
|
||||
n1 = BigDecimal.new("1")
|
||||
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
|
||||
assert_equal(nil, BigDecimal.new("NaN") <=> n1)
|
||||
assert_equal(false, BigDecimal.new("NaN") > n1)
|
||||
end
|
||||
|
||||
def test_cmp_failing_coercion
|
||||
n1 = BigDecimal.new("1")
|
||||
assert_equal(nil, n1 <=> nil)
|
||||
assert_raise(ArgumentError){n1 > nil}
|
||||
end
|
||||
|
||||
def test_cmp_coerce
|
||||
n1 = BigDecimal.new("1")
|
||||
n2 = BigDecimal.new("2")
|
||||
o1 = Object.new; def o1.coerce(x); [x, BigDecimal.new("1")]; end
|
||||
|
|
Загрузка…
Ссылка в новой задаче