mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 02:23:59 +02:00
bigdecimal.c: check underflow
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): check underflow since strtod() sets errno to ERANGE at underflow too. [ruby-core:47342] [Bug #6944] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aa7dc0f305
commit
d7ca01a73a
3 changed files with 36 additions and 8 deletions
|
@ -540,15 +540,35 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||
assert_kind_of(Float, x .to_f)
|
||||
assert_kind_of(Float, (-x).to_f)
|
||||
|
||||
bug6944 = '[ruby-core:47342]'
|
||||
|
||||
BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, true)
|
||||
assert_raise(FloatDomainError) {
|
||||
BigDecimal("1e#{Float::MIN_10_EXP - 2*Float::DIG}").to_f }
|
||||
assert_raise(FloatDomainError) {
|
||||
BigDecimal("-1e#{Float::MIN_10_EXP - 2*Float::DIG}").to_f }
|
||||
x = "1e#{Float::MIN_10_EXP - 2*Float::DIG}"
|
||||
assert_raise(FloatDomainError, x) {BigDecimal(x).to_f}
|
||||
x = "-#{x}"
|
||||
assert_raise(FloatDomainError, x) {BigDecimal(x).to_f}
|
||||
x = "1e#{Float::MIN_10_EXP - Float::DIG}"
|
||||
assert_nothing_raised(FloatDomainError, x) {
|
||||
assert_in_delta(0.0, BigDecimal(x).to_f, 10**Float::MIN_10_EXP, bug6944)
|
||||
}
|
||||
x = "-#{x}"
|
||||
assert_nothing_raised(FloatDomainError, x) {
|
||||
assert_in_delta(0.0, BigDecimal(x).to_f, 10**Float::MIN_10_EXP, bug6944)
|
||||
}
|
||||
|
||||
BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, false)
|
||||
assert_equal( 0.0, BigDecimal("1e#{Float::MIN_10_EXP - 2*Float::DIG}").to_f)
|
||||
assert_equal(-0.0, BigDecimal("-1e#{Float::MIN_10_EXP - 2*Float::DIG}").to_f)
|
||||
x = "1e#{Float::MIN_10_EXP - 2*Float::DIG}"
|
||||
assert_equal( 0.0, BigDecimal(x).to_f, x)
|
||||
x = "-#{x}"
|
||||
assert_equal(-0.0, BigDecimal(x).to_f, x)
|
||||
x = "1e#{Float::MIN_10_EXP - Float::DIG}"
|
||||
assert_nothing_raised(FloatDomainError, x) {
|
||||
assert_in_delta(0.0, BigDecimal(x).to_f, 10**Float::MIN_10_EXP, bug6944)
|
||||
}
|
||||
x = "-#{x}"
|
||||
assert_nothing_raised(FloatDomainError, x) {
|
||||
assert_in_delta(0.0, BigDecimal(x).to_f, 10**Float::MIN_10_EXP, bug6944)
|
||||
}
|
||||
end
|
||||
|
||||
def test_coerce
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue