bigdecimal.c: fix FloatDomainError
* ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): consider non-finite float values not to raise FloatDomainError. [ruby-core:75682] [Bug #12414] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb2a99822e
commit
4a574f7ad9
@ -1,3 +1,9 @@
|
|||||||
|
Mon May 23 12:30:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): consider
|
||||||
|
non-finite float values not to raise FloatDomainError.
|
||||||
|
[ruby-core:75682] [Bug #12414]
|
||||||
|
|
||||||
Mon May 23 12:21:18 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
Mon May 23 12:21:18 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* array.c (rb_ary_fill): suppress warnings: 'item' may be used
|
* array.c (rb_ary_fill): suppress warnings: 'item' may be used
|
||||||
|
@ -239,6 +239,12 @@ again:
|
|||||||
if (prec < 0) goto unable_to_coerce_without_prec;
|
if (prec < 0) goto unable_to_coerce_without_prec;
|
||||||
if (prec > DBL_DIG+1) goto SomeOneMayDoIt;
|
if (prec > DBL_DIG+1) goto SomeOneMayDoIt;
|
||||||
d = RFLOAT_VALUE(v);
|
d = RFLOAT_VALUE(v);
|
||||||
|
if (!isfinite(d)) {
|
||||||
|
pv = VpCreateRbObject(prec, NULL);
|
||||||
|
pv->sign = isnan(d) ? VP_SIGN_NaN :
|
||||||
|
d > 0 ? VP_SIGN_POSITIVE_INFINITE : VP_SIGN_NEGATIVE_FINITE;
|
||||||
|
return pv;
|
||||||
|
}
|
||||||
if (d != 0.0) {
|
if (d != 0.0) {
|
||||||
v = rb_funcall(v, id_to_r, 0);
|
v = rb_funcall(v, id_to_r, 0);
|
||||||
goto again;
|
goto again;
|
||||||
|
@ -459,6 +459,18 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||||||
assert_equal(false, BigDecimal.new("NaN") > n1)
|
assert_equal(false, BigDecimal.new("NaN") > n1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cmp_float_nan
|
||||||
|
assert_equal(nil, BigDecimal.new("1") <=> Float::NAN)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_cmp_float_pos_inf
|
||||||
|
assert_equal(-1, BigDecimal.new("1") <=> Float::INFINITY)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_cmp_float_neg_inf
|
||||||
|
assert_equal(+1, BigDecimal.new("1") <=> -Float::INFINITY)
|
||||||
|
end
|
||||||
|
|
||||||
def test_cmp_failing_coercion
|
def test_cmp_failing_coercion
|
||||||
n1 = BigDecimal.new("1")
|
n1 = BigDecimal.new("1")
|
||||||
assert_equal(nil, n1 <=> nil)
|
assert_equal(nil, n1 <=> nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user