mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
No FloatDomainError at non-finitive number if exception: false
[ruby-core:91021] [Bug #15525] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
62c17a2f21
commit
4e28fdf417
2 changed files with 10 additions and 0 deletions
1
object.c
1
object.c
|
@ -3159,6 +3159,7 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception)
|
|||
double f;
|
||||
if (base != 0) goto arg_error;
|
||||
f = RFLOAT_VALUE(val);
|
||||
if (!raise_exception && !isfinite(f)) return Qnil;
|
||||
if (FIXABLE(f)) return LONG2FIX((long)f);
|
||||
return rb_dbl2big(f);
|
||||
}
|
||||
|
|
|
@ -175,6 +175,15 @@ class TestInteger < Test::Unit::TestCase
|
|||
def o.to_int; raise; end
|
||||
assert_equal(nil, Integer(o, exception: false))
|
||||
}
|
||||
assert_nothing_raised(FloatDomainError) {
|
||||
assert_equal(nil, Integer(Float::INFINITY, exception: false))
|
||||
}
|
||||
assert_nothing_raised(FloatDomainError) {
|
||||
assert_equal(nil, Integer(-Float::INFINITY, exception: false))
|
||||
}
|
||||
assert_nothing_raised(FloatDomainError) {
|
||||
assert_equal(nil, Integer(Float::NAN, exception: false))
|
||||
}
|
||||
|
||||
assert_raise(ArgumentError) {
|
||||
Integer("1z", exception: true)
|
||||
|
|
Loading…
Add table
Reference in a new issue