mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (rb_big_fdiv): checks whether the given second argument
can be converted to float properly. * numeric.c (fix_fdiv): calls rb_big_fdiv when the given second argument is a bignum. * rational.c (nurat_fdiv): should calculate Float(x/y), not Float(x)/Float(y). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bbd2b5e9bd
commit
b6849b2502
5 changed files with 91 additions and 47 deletions
|
@ -4,6 +4,9 @@ class TestBignum < Test::Unit::TestCase
|
|||
def setup
|
||||
@verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
@fmax = Float::MAX.to_i
|
||||
@fmax2 = @fmax * 2
|
||||
@big = (1 << 63) - 1
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -395,4 +398,19 @@ class TestBignum < Test::Unit::TestCase
|
|||
e = assert_raise(RangeError) {(1 << big).to_s}
|
||||
assert_match(/too big to convert/, e.message)
|
||||
end
|
||||
|
||||
def test_fix_fdiv
|
||||
assert_not_equal(0, 1.fdiv(@fmax2))
|
||||
assert_in_delta(0.5, 1.fdiv(@fmax2) * @fmax, 0.01)
|
||||
end
|
||||
|
||||
def test_big_fdiv
|
||||
assert_equal(1, @big.fdiv(@big))
|
||||
assert_not_equal(0, @big.fdiv(@fmax2))
|
||||
assert_not_equal(0, @fmax2.fdiv(@big))
|
||||
assert_not_equal(0, @fmax2.fdiv(@fmax2))
|
||||
assert_in_delta(0.5, @fmax.fdiv(@fmax2), 0.01)
|
||||
assert_in_delta(1.0, @fmax2.fdiv(@fmax2), 0.01)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue